DataGridViewCheckBoxCell.GetFormattedValue(Object, Int32, DataGridViewCellStyle, TypeConverter, TypeConverter, DataGridViewDataErrorContexts) 方法

定義

取得儲存格資料的格式化值。Gets the formatted value of the cell's data.

protected:
 override 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 override 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);
override this.GetFormattedValue : obj * int * DataGridViewCellStyle * System.ComponentModel.TypeConverter * System.ComponentModel.TypeConverter * System.Windows.Forms.DataGridViewDataErrorContexts -> obj
Protected Overrides 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

要格式化的值。The value to be formatted.

rowIndex
Int32

儲存格的父資料列索引。The index of the cell's parent row.

cellStyle
DataGridViewCellStyle

DataGridViewCellStyle 對儲存格有作用。The DataGridViewCellStyle in effect for the cell.

valueTypeConverter
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,此格式化實值型別可提供從實值型別轉換的自訂轉換作業,如果不需要這種自訂轉換,則為 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 值的位元 (Bitwise) 組合,其描述需要此格式化值的內容。A bitwise combination of DataGridViewDataErrorContexts values describing the context in which the formatted value is needed.

傳回

Object

儲存格的資料在套用格式化之後的值;如果儲存格不是 DataGridView 控制項的一部分,則為 nullThe value of the cell's data after formatting has been applied or null if the cell is not part of a DataGridView control.

備註

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

這個方法會先嘗試 value Boolean CheckState 使用 TrueValueFalseValueIndeterminateValue 屬性(如果已設定)來轉換成或值。This method first attempts to convert value to a Boolean or CheckState value using the TrueValue, FalseValue, and IndeterminateValue properties if they have been set.

如果轉換失敗, DataGridView.DataError 就會發生此事件。If the conversion is unsuccessful, the DataGridView.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.

如果轉換成功,或有事件的處理常式,但 DataError 未將 DataGridViewDataErrorEventArgs.ThrowException 屬性設定為 true ,則 DataGridView.CellFormatting 會發生此事件。If the conversion is successful 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.

CellFormatting事件處理常式可以同時修改 valuecellStyleA CellFormatting event handler can modify both value and cellStyle. 但是,如果處理常式未將 DataGridViewCellFormattingEventArgs.FormattingApplied 屬性設定為 true ,則這個方法會 value 使用物件的格式化屬性來格式化 cellStyleIf the handler does not set the DataGridViewCellFormattingEventArgs.FormattingApplied property to true, however, this method formats value using the formatting properties of the cellStyle object. 這可能會導致額外的 DataError 事件。This can result in an additional DataError event.

如果格式化成功且 context 參數值包含 ClipboardContent 值,則這個方法會傳回 String 要複製到剪貼簿的格式化值版本。If formatting is successful and the context parameter value includes the ClipboardContent value, this method returns the String version of the formatted value for copying to the Clipboard. 否則,這個方法會傳回格式化的值,以便顯示在 DataGridView 控制項中。Otherwise, this method returns the formatted value for display in the DataGridView control.

適用於

另請參閱