ConvertEventArgs.Value 속성

정의

ConvertEventArgs의 값을 가져오거나 설정합니다.

public:
 property System::Object ^ Value { System::Object ^ get(); void set(System::Object ^ value); };
public object Value { get; set; }
public object? Value { get; set; }
member this.Value : obj with get, set
Public Property Value As Object

속성 값

ConvertEventArgs의 값입니다.

예제

다음 코드 예제에서는 Binding, 추가 ConvertEventHandler 둘 다에 대리자를 ParseFormat 이벤트를 사용 하 여는 DataBindings 추가할 속성을 BindingBindingsCollectionTextBox 컨트롤입니다. DecimalToCurrencyString 이벤트 대리자에 추가 되는 Format 이벤트를 사용 하는 ToString 바인딩된 값의 서식을 지정 하는 방법 (을 Decimal 형식) 통화로. CurrencyStringToDecimal 에 추가 되는 이벤트 대리자를 Parse 이벤트를 컨트롤에 의해 표시 되는 값을 변환 다시는 Decimal 형식입니다.

private:
   void DecimalToCurrencyString( Object^ /*sender*/, ConvertEventArgs^ cevent )
   {
      // The method converts only to string type. Test this using the DesiredType.
      if ( cevent->DesiredType != String::typeid )
      {
         return;
      }
      
      // Use the ToString method to format the value as currency ("c").
      cevent->Value = ( (Decimal^)(cevent->Value) )->ToString( "c" );
   }

   void CurrencyStringToDecimal( Object^ /*sender*/, ConvertEventArgs^ cevent )
   {
      // The method converts back to decimal type only. 
      if ( cevent->DesiredType != Decimal::typeid )
      {
         return;
      }
      
      // Converts the string back to decimal using the static Parse method.
      cevent->Value = Decimal::Parse( cevent->Value->ToString(),
         NumberStyles::Currency, nullptr );
   }

   void BindControl()
   {
      // Creates the binding first. The OrderAmount is typed as Decimal.
      Binding^ b = gcnew Binding(
         "Text",ds,"customers.custToOrders.OrderAmount" );
      
      // Adds the delegates to the events.
      b->Format += gcnew ConvertEventHandler(
         this, &Form1::DecimalToCurrencyString );
      b->Parse += gcnew ConvertEventHandler(
         this, &Form1::CurrencyStringToDecimal );
      text1->DataBindings->Add( b );
   }
private void DecimalToCurrencyString(object sender, ConvertEventArgs cevent)
{
   // The method converts only to string type. Test this using the DesiredType.
   if(cevent.DesiredType != typeof(string)) return;

   // Use the ToString method to format the value as currency ("c").
   cevent.Value = ((decimal) cevent.Value).ToString("c");
}

private void CurrencyStringToDecimal(object sender, ConvertEventArgs cevent)
{
   // The method converts back to decimal type only. 
   if(cevent.DesiredType != typeof(decimal)) return;

   // Converts the string back to decimal using the static Parse method.
   cevent.Value = Decimal.Parse(cevent.Value.ToString(),
   NumberStyles.Currency, null);
}

private void BindControl()
{
   // Creates the binding first. The OrderAmount is typed as Decimal.
   Binding b = new Binding
   ("Text", ds, "customers.custToOrders.OrderAmount");
   // Adds the delegates to the events.
   b.Format += new ConvertEventHandler(DecimalToCurrencyString);
   b.Parse += new ConvertEventHandler(CurrencyStringToDecimal);
   text1.DataBindings.Add(b);
}
Private Sub DecimalToCurrencyString(sender As Object, cevent As ConvertEventArgs)
   ' The method converts only to string type. Test this using the DesiredType.
   If Not cevent.DesiredType Is GetType(String) Then
      Return
   End If 
   ' Use the ToString method to format the value as currency ("c").
   cevent.Value = CDec(cevent.Value).ToString("c")
End Sub
 
 
Private Sub CurrencyStringToDecimal(sender As Object, cevent As ConvertEventArgs)
   ' The method converts back to decimal type only. 
   If Not cevent.DesiredType Is GetType(Decimal) Then
      Return
   End If 
   ' Converts the string back to decimal using the shared Parse method.
   cevent.Value = Decimal.Parse(cevent.Value.ToString, _
   NumberStyles.Currency, nothing)

End Sub
 
 
Private Sub BindControl()
   ' Creates the binding first. The OrderAmount is typed as Decimal.
   Dim b As New Binding("Text", ds, "customers.custToOrders.OrderAmount")
   ' Adds the delegates to the events.
   AddHandler b.Format, AddressOf DecimalToCurrencyString
   AddHandler b.Parse, AddressOf CurrencyStringToDecimal
   text1.DataBindings.Add(b)
End Sub

설명

에 포함 된 값을 Value 속성이 있는 이벤트에 종속는 ConvertEventArgs 반환 됩니다. 합니다 ConvertEventArgs 에서 반환 될 수는 Format 이벤트 또는 Parse 이벤트입니다.

경우는 ConvertEventArgs 에 반환 됩니다는 Format 이벤트는 Value 데이터 원본의 형식이 지정 되지 않은 속성 값을 포함 하는 속성. 내 합니다 Format 이벤트 속성 값을 읽고, 값의 서식을 지정 및 다시 설정는 Value 속성을 데이터 바인딩된 컨트롤에 표시 되는 값을 설정할 새 (서식이 지정 된) 값을 합니다.

경우는 ConvertEventArgs 에 반환 됩니다는 Parse 데이터 바인딩된 컨트롤의 사용자 지정 형식의 값을 포함 하는 이벤트 속성입니다. 내는 Parse 이벤트 형식이 지정 된 값, 분석 하 고 읽고 해야 데이터 원본으로 동일한 데이터 형식으로 다시 변환 합니다. 재설정할 수 있습니다는 Value 는 형식이 지정 되지 않은 속성 값을 하므로 데이터 원본의 값을 설정 합니다. 데이터 원본 유형을 확인 하려면를 DesiredType 속성 값입니다.

적용 대상

추가 정보