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 属性设置为 true 而引起的。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. 通常情况下,可将该异常对象强制转换为类型 FormatExceptionThe 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. 否则,此方法会将单元格值转换为属性所指示类型的等效显示值 FormattedValueTypeOtherwise, 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.ThrowExceptiontrue ,则会引发异常。If there is no handler for this event or the handler sets the DataGridViewDataErrorEventArgs.ThrowException property to true, an exception is thrown.

如果参数包含值,则重写此方法的派生类通常将返回单元值的字符串表示形式 context ClipboardContentDerived classes that override this method will typically return a string representation of the cell value if the context argument includes the ClipboardContent value.