DataGridViewCell.GetFormattedValue(Object, Int32, DataGridViewCellStyle, TypeConverter, TypeConverter, DataGridViewDataErrorContexts) DataGridViewCell.GetFormattedValue(Object, Int32, DataGridViewCellStyle, TypeConverter, TypeConverter, DataGridViewDataErrorContexts) DataGridViewCell.GetFormattedValue(Object, Int32, DataGridViewCellStyle, TypeConverter, TypeConverter, DataGridViewDataErrorContexts) DataGridViewCell.GetFormattedValue(Object, Int32, DataGridViewCellStyle, TypeConverter, TypeConverter, DataGridViewDataErrorContexts) Method

Definition

Gets the value of the cell as formatted for display.

protected:
 virtual System::Object ^ GetFormattedValue(System::Object ^ value, int rowIndex, System::Windows::Forms::DataGridViewCellStyle ^ % cellStyle, System::ComponentModel::TypeConverter ^ valueTypeConverter, System::ComponentModel::TypeConverter ^ formattedValueTypeConverter, System::Windows::Forms::DataGridViewDataErrorContexts context);
protected virtual object GetFormattedValue (object value, int rowIndex, ref System.Windows.Forms.DataGridViewCellStyle cellStyle, System.ComponentModel.TypeConverter valueTypeConverter, System.ComponentModel.TypeConverter formattedValueTypeConverter, System.Windows.Forms.DataGridViewDataErrorContexts context);
abstract member GetFormattedValue : obj * int * DataGridViewCellStyle * System.ComponentModel.TypeConverter * System.ComponentModel.TypeConverter * System.Windows.Forms.DataGridViewDataErrorContexts -> obj
override this.GetFormattedValue : obj * int * DataGridViewCellStyle * System.ComponentModel.TypeConverter * System.ComponentModel.TypeConverter * System.Windows.Forms.DataGridViewDataErrorContexts -> obj
Protected Overridable Function GetFormattedValue (value As Object, rowIndex As Integer, ByRef cellStyle As DataGridViewCellStyle, valueTypeConverter As TypeConverter, formattedValueTypeConverter As TypeConverter, context As DataGridViewDataErrorContexts) As Object

Parameters

value
Object Object Object Object

The value to be formatted.

rowIndex
Int32 Int32 Int32 Int32

The index of the cell's parent row.

valueTypeConverter
TypeConverter TypeConverter TypeConverter TypeConverter

A TypeConverter associated with the value type that provides custom conversion to the formatted value type, or null if no such custom conversion is needed.

formattedValueTypeConverter
TypeConverter TypeConverter TypeConverter TypeConverter

A TypeConverter associated with the formatted value type that provides custom conversion from the value type, or null if no such custom conversion is needed.

context
DataGridViewDataErrorContexts DataGridViewDataErrorContexts DataGridViewDataErrorContexts DataGridViewDataErrorContexts

A bitwise combination of DataGridViewDataErrorContexts values describing the context in which the formatted value is needed.

Returns

The formatted value of the cell or null if the cell does not belong to a DataGridView control.

Exceptions

Formatting failed and either there is no handler for the DataError event of the DataGridView control or the handler set the ThrowException property to true. The exception object can typically be cast to type FormatException.

Remarks

The DataGridView control calls this method to convert a cell value into an equivalent display value of the type indicated by the FormattedValueType property. The control passes the cell value to this method in the value parameter.

This method raises the DataGridView.CellFormatting event. A handler for this event can modify both the value and cellStyle parameters. If the handler does not set the DataGridViewCellFormattingEventArgs.FormattingApplied property to true, however, this method formats value using the formatting properties of the cellStyle object.

Note

This method does not convert value to the DataGridViewCellStyle.NullValue property value for values equal to the DataGridViewCellStyle.DataSourceNullValue property value when DataSourceNullValue is set to a value other than DBNull.Value or null. In this case, you can handle the DataGridView.CellFormatting event to display the NullValue property value. For more information, see the code example in DataSourceNullValue.

If formatting is unsuccessful, the DataError event occurs. If there is no handler for this event or the handler sets the DataGridViewDataErrorEventArgs.ThrowException property to true, an exception is thrown.

Derived classes that override this method will typically return a string representation of the cell value if the context argument includes the ClipboardContent value.

Applies to

See also