DataGridViewCell.GetEditedFormattedValue(Int32, DataGridViewDataErrorContexts) 方法


傳回目前已格式化的儲存格值,不管儲存格是否處於編輯模式,而值是否尚未認可。Returns the current, formatted value of the cell, regardless of whether the cell is in edit mode and the value has not been committed.

 System::Object ^ GetEditedFormattedValue(int rowIndex, System::Windows::Forms::DataGridViewDataErrorContexts context);
public object GetEditedFormattedValue (int rowIndex, System.Windows.Forms.DataGridViewDataErrorContexts context);
member this.GetEditedFormattedValue : int * System.Windows.Forms.DataGridViewDataErrorContexts -> obj
Public Function GetEditedFormattedValue (rowIndex As Integer, context As DataGridViewDataErrorContexts) As Object



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


DataGridViewDataErrorContexts 值的位元組合,指定資料錯誤內容。A bitwise combination of DataGridViewDataErrorContexts values that specifies the data error context.


DataGridViewCell 目前的已格式化值。The current, formatted value of the DataGridViewCell.


指定的 rowIndex 小於 0 或大於控制項中資料列數減 1。The specified rowIndex is less than 0 or greater than the number of rows in the control minus 1.

ColumnIndex 小於 0,表示儲存格是資料列行首儲存格。ColumnIndex is less than 0, indicating that the cell is a row header cell.

格式化失敗,而且 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.


如果儲存格處於編輯模式,這個方法會傳回編輯資料格或編輯控制項的目前值。This method returns the current value of the editing cell or editing control if the cell is in edit mode. 否則,這個方法會將儲存格值轉換成 FormattedValueType 屬性所指示之型別的對等顯示值。Otherwise, this method converts the cell value into an equivalent display value of the type indicated by the FormattedValueType property. 這會引發 DataGridView.CellFormatting 事件,而您可以處理此事件以自訂值轉換。This raises the DataGridView.CellFormatting event, which you can handle to customize the value conversion.

如果格式不成功,就會發生 DataGridView.DataError 事件。If formatting 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.

如果 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.