ConvertEventArgs.Value ConvertEventArgs.Value ConvertEventArgs.Value ConvertEventArgs.Value Property

定義

ConvertEventArgs の値を取得または設定します。Gets or sets the value of the ConvertEventArgs.

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

プロパティ値

ConvertEventArgs の値です。The value of the ConvertEventArgs.

次のコード例を作成します、 Binding、追加、ConvertEventHandler両方にデリゲート、ParseFormatイベント、および使用、DataBindingsプロパティを追加する、BindingBindingsCollectionTextBoxコントロール。The following code example creates a Binding, adds a ConvertEventHandler delegate to both the Parse and Format events, and uses the DataBindings property to add the Binding to the BindingsCollection of a TextBox control. DecimalToCurrencyStringに追加されるイベント デリゲート、Formatイベントを使用して、ToStringバインドされている値の書式を指定するメソッド (、Decimal型) の通貨として。The DecimalToCurrencyString event delegate, which is added to the Format event, uses the ToString method to format the bound value (a Decimal type) as currency. CurrencyStringToDecimalに追加されるイベント デリゲート、Parseイベント、変換、コントロールによって表示される値に戻す、Decimal型。The CurrencyStringToDecimal event delegate, which is added to the Parse event, converts the value displayed by the control back to the Decimal type.

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 'DecimalToCurrencyString
 
 
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 'CurrencyStringToDecimal
 
 
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 'BindControl

注釈

含まれる値、Valueプロパティをイベントに依存、ConvertEventArgsが返されます。The value contained by the Value property depends on the event in which the ConvertEventArgs is returned. ConvertEventArgsいずれかで返されることができます、FormatイベントまたはParseイベント。The ConvertEventArgs can be returned in either the Format event or the Parse event.

ときに、ConvertEventArgsで返される、 Format 、イベント、Valueプロパティには、データ ソースの書式設定されていないプロパティの値が含まれています。When the ConvertEventArgs is returned in the Format event, the Value property contains the unformatted property value of the data source. 内で、Formatイベント、プロパティ値の読み取り、値を書式設定およびリセット、Valueプロパティをデータ バインド コントロールに表示される値を設定するため、新しい (書式設定された) 値。Within the Format event, you can read the property value, format the value, and reset the Value property to the new (formatted) value, thereby setting the value displayed in the data-bound control.

ときに、ConvertEventArgsで返される、Parseイベント、プロパティには、データ バインド コントロールのカスタム書式設定された値が含まれています。When the ConvertEventArgs is returned in the Parse event, the property contains the custom-formatted value of the data-bound control. 内で、Parseイベント、する必要があります、書式設定された値の読み取り、解析し、およびそれをデータ ソースと同じデータ型に変換します。Within the Parse event, you must read the formatted value, parse it, and convert it back to the same data type as the data source. リセットすることができますし、Valueプロパティを書式設定されていない値に設定して、それによって、データ ソースの値を設定します。You can then reset the Value property to the unformatted value, and thereby set the value of the data source. データ ソースの種類を判断するに調べて、DesiredTypeプロパティの値。To determine the type of the data source, examine the DesiredType property value.

適用対象

こちらもご覧ください