DataGridViewComboBoxCell::GetFormattedValue Method (Object^, Int32, DataGridViewCellStyle^%, TypeConverter^, TypeConverter^, DataGridViewDataErrorContexts)
Gets the formatted value of the cell's data.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
protected: virtual Object^ GetFormattedValue( Object^ value, int rowIndex, DataGridViewCellStyle^% cellStyle, TypeConverter^ valueTypeConverter, TypeConverter^ formattedValueTypeConverter, DataGridViewDataErrorContexts context ) override
Parameters
- value
-
Type:
System::Object^
The value to be formatted.
- rowIndex
-
Type:
System::Int32
The index of the cell's parent row.
- cellStyle
-
Type:
System.Windows.Forms::DataGridViewCellStyle^%
The DataGridViewCellStyle in effect for the cell.
- valueTypeConverter
-
Type:
System.ComponentModel::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
-
Type:
System.ComponentModel::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
-
Type:
System.Windows.Forms::DataGridViewDataErrorContexts
A bitwise combination of DataGridViewDataErrorContexts values describing the context in which the formatted value is needed.
Return Value
Type: System::Object^The value of the cell's data after formatting has been applied or null if the cell is not part of a DataGridView control.
| Exception | Condition |
|---|---|
| Exception | 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 for type conversion errors or to type ArgumentException if value cannot be found in the DataSource or the Items collection. |
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 first determines whether value is valid by determining whether one of the following conditions is met.
value is present in the DataSource or the Items collection.
value is null or DBNull::Value.
value is String::Empty and the ValueType property value represents the String type.
If value is not valid, the DataGridView::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.
If value is valid or there is a handler for the DataError event and it does not set the DataGridViewDataErrorEventArgs::ThrowException property to true, the DataGridView::CellFormatting event occurs.
A CellFormatting event handler can modify both value and cellStyle. 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. This can result in an additional DataError event.
If formatting is successful, this method returns the formatted value for display in the DataGridView control.
Available since 2.0
FormattedValueType
DataSource
Items
DataGridView
DataGridViewCellStyle
TypeConverter
DataGridViewDataErrorContexts
DataGridViewCellStyle::Format
DataGridView::CellFormatting
DataGridView::DataError
DataGridViewCell::GetFormattedValue
ParseFormattedValue
DataGridViewComboBoxCell Class
System.Windows.Forms Namespace