System.Windows.Forms.Binding.Format Event

Occurs when the property of a control is bound to a data value.


public event ConvertEventHandler Format


The Binding.Format event is raised when data is pushed from the data source into the control. You can handle the Binding.Format event to convert unformatted data from the data source into formatted data for display. When data is pulled from the control into the data source, the Binding.Parse event is raised to unformat the displayed value, then the Binding.Format event occurs to reformat the data for display. This ensures that the bound control displays correctly formatted data regardless of whether the user enters formatted or unformatted data in the control.

The Binding.Format and Binding.Parse events allow you to create custom formats for displaying data. For example, if the data in a table is of type decimal, you can display the data in the local currency format by setting the ConvertEventArgs.Value property of the System.Windows.Forms.ConvertEventArgs to the formatted value in the Binding.Format event. You must consequently unformat the displayed value in the Binding.Parse event.

The Binding.Format event occurs whenever the BindingManagerBase.Current value of the System.Windows.Forms.BindingManagerBase changes, which includes:

The Binding.Format event also occurs after the Binding.Parse event. For example, when a control loses focus, its contents are parsed. Immediately afterward, as new data is pushed into the control, the Binding.Format event occurs allowing the new contents to be formatted.

For more information about handling events, see Consuming Events.


Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0,