Export (0) Print
Expand All
Expand Minimize

DataGridViewCell.GetFormattedValue Method

Gets the value of the cell as formatted for display.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

protected virtual Object GetFormattedValue (
	Object value,
	int rowIndex,
	ref DataGridViewCellStyle cellStyle,
	TypeConverter valueTypeConverter,
	TypeConverter formattedValueTypeConverter,
	DataGridViewDataErrorContexts context
)
protected Object GetFormattedValue (
	Object value, 
	int rowIndex, 
	/** @ref */ DataGridViewCellStyle cellStyle, 
	TypeConverter valueTypeConverter, 
	TypeConverter formattedValueTypeConverter, 
	DataGridViewDataErrorContexts context
)
Not applicable.

Parameters

value

The value to be formatted.

rowIndex

The index of the cell's parent row.

cellStyle

The DataGridViewCellStyle in effect for the cell.

valueTypeConverter

A TypeConverter associated with the value type that provides custom conversion to the formatted value type, or a null reference (Nothing in Visual Basic) if no such custom conversion is needed.

formattedValueTypeConverter

A TypeConverter associated with the formatted value type that provides custom conversion from the value type, or a null reference (Nothing in Visual Basic) if no such custom conversion is needed.

context

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

Return Value

The formatted value of the cell or a null reference (Nothing in Visual Basic) if the cell does not belong to a DataGridView control.

Exception typeCondition

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.

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.

NoteNote:

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 a null reference (Nothing in Visual Basic). 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.

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft