This documentation is archived and is not being maintained.

ConvertEventArgs.Value Property

Gets or sets the value of the ConvertEventArgs.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public Object Value { get; set; }

Property Value

Type: System.Object
The value of the ConvertEventArgs.

The value contained by the Value property depends on the event in which the ConvertEventArgs is returned. The ConvertEventArgs can be returned in either the Format event or the Parse event.

When the ConvertEventArgs is returned in the Format event, the Value property contains the unformatted property value of the data source. 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.

When the ConvertEventArgs is returned in the Parse event, the property contains the custom-formatted value of the data-bound control. 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. You can then reset the Value property to the unformatted value, and thereby set the value of the data source. To determine the type of the data source, examine the DesiredType property value.

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. 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. 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 != 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);

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0