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

定義

取得儲存格的格式化值,以供顯示。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

參數

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

與實值型別相關的 TypeConverter,此實值型別可提供轉換為格式化實值型別的自訂轉換作業,如果不需要這種自訂轉換,則為 nullA 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

與格式化實值型別相關的 TypeConverter,此格式化實值型別可提供從實值型別轉換的自訂轉換作業,如果不需要這種自訂轉換,則為 nullA 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

DataGridViewDataErrorContexts 值的位元 (Bitwise) 組合,其描述需要此格式化值的內容。A bitwise combination of DataGridViewDataErrorContexts values describing the context in which the formatted value is needed.

傳回

如果儲存格不屬於 DataGridView 控制項,則為儲存格的已格式化值或 nullThe formatted value of the cell or null if the cell does not belong to a DataGridView control.

例外狀況

格式化失敗,而且 DataError 控制項的 DataGridView 事件沒有處理常式,或是該處理常式將 ThrowException 屬性設定為 trueFormatting failed and either there is no handler for the DataError event of the DataGridView control or the handler set the ThrowException property to true. 例外狀況物件通常可轉換成 FormatException 類型。The exception object can typically be cast to type FormatException.

備註

控制項會呼叫這個方法,將儲存格值轉換成FormattedValueType屬性所指示之型別的對等顯示值。 DataGridViewThe DataGridView control calls this method to convert a cell value into an equivalent display value of the type indicated by the FormattedValueType property. 控制項會將資料格值傳遞給value參數中的這個方法。The control passes the cell value to this method in the value parameter.

這個方法會引發DataGridView.CellFormatting事件。This method raises the DataGridView.CellFormatting event. 這個事件的處理常式可以同時value修改和cellStyle參數。A handler for this event can modify both the value and cellStyle parameters. 不過,如果處理常式並未將DataGridViewCellFormattingEventArgs.FormattingApplied屬性設定true為,則這個方法會value使用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.

注意

value DataGridViewCellStyle.NullValue DataGridViewCellStyle.DataSourceNullValue DataSourceNullValue當設定為或null以外的值時,這個方法不會轉換成等於屬性值的值屬性值。 DBNull.ValueThis 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. 在此情況下,您可以處理DataGridView.CellFormatting事件以NullValue顯示內容值。In this case, you can handle the DataGridView.CellFormatting event to display the NullValue property value. 如需詳細資訊,請參閱DataSourceNullValue 中的程式碼範例。For more information, see the code example in DataSourceNullValue.

如果格式不成功,就DataError會發生此事件。If formatting is unsuccessful, the DataError event occurs. 如果此事件沒有處理常式,或處理常式將DataGridViewDataErrorEventArgs.ThrowException屬性設定為true,則會擲回例外狀況。If there is no handler for this event or the handler sets the DataGridViewDataErrorEventArgs.ThrowException property to true, an exception is thrown.

如果context引數ClipboardContent包含值,則覆寫這個方法的衍生類別通常會傳回資料格值的字串表示。Derived classes that override this method will typically return a string representation of the cell value if the context argument includes the ClipboardContent value.

適用於

另請參閱