System.Windows.Forms.DataGridViewCellFormattingEventHandler Delegate

Represents the method that will handle the DataGridView.CellFormatting event of a System.Windows.Forms.DataGridView.

Syntax

public delegate void DataGridViewCellFormattingEventHandler (object sender, DataGridViewCellFormattingEventArgs e)

Parameters

sender
Documentation for this section has not yet been entered.
e
Documentation for this section has not yet been entered.

Remarks

Handle the DataGridView.CellFormatting event to customize the conversion of a cell value into a format suitable for display or to customize the appearance of a cell depending on its state or value.

The DataGridView.CellFormatting event occurs every time each cell is painted, so you should avoid lengthy processing when handling this event. This event also occurs when the cell DataGridViewCell.FormattedValue is retrieved or its DataGridViewCell.GetFormattedValue(object, int, DataGridViewCellStyle@, System.ComponentModel.TypeConverter, System.ComponentModel.TypeConverter, DataGridViewDataErrorContexts) method is called.

When you handle the DataGridView.CellFormatting event, the ConvertEventArgs.Value property is initialized with the cell value. If you provide custom conversion from the cell value to the display value, set the ConvertEventArgs.Value property to the converted value, ensuring that the new value is of the type specified by the cell DataGridViewCell.FormattedValueType property. To indicate that no further value formatting is necessary, set the DataGridViewCellFormattingEventArgs.FormattingApplied property to true.

When the event handler completes, if the ConvertEventArgs.Value is null or is not of the correct type, or the DataGridViewCellFormattingEventArgs.FormattingApplied property is false, the ConvertEventArgs.Value is formatted using the DataGridViewCellStyle.Format, DataGridViewCellStyle.NullValue, DataGridViewCellStyle.DataSourceNullValue, and DataGridViewCellStyle.FormatProvider properties of the cell style returned by the DataGridViewCellFormattingEventArgs.CellStyle property, which is initialized using the cell DataGridViewCell.InheritedStyle property.

Regardless of the value of the DataGridViewCellFormattingEventArgs.FormattingApplied property, the display properties of the object returned by the DataGridViewCellFormattingEventArgs.CellStyle property are used to render the cell.

For more information about custom formatting using the DataGridView.CellFormatting event, see How to: Customize Data Formatting in the Windows Forms DataGridView Control.

To avoid performance penalties when handling this event, access the cell through the parameters of the event handler rather than accessing the cell directly.

To customize the conversion of a formatted, user-specified value into an actual cell value, handle the DataGridView.CellParsing event.

For more information about handling events, see Consuming Events.

When you create a System.Windows.Forms.DataGridViewCellFormattingEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event-handler delegates, see Events and Delegates.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0