DataGridViewCell.ParseFormattedValue(Object, DataGridViewCellStyle, TypeConverter, TypeConverter) 方法


将为便于显示而进行了格式设置的值转换为实际的单元格值。Converts a value formatted for display to an actual cell value.

 virtual System::Object ^ ParseFormattedValue(System::Object ^ formattedValue, System::Windows::Forms::DataGridViewCellStyle ^ cellStyle, System::ComponentModel::TypeConverter ^ formattedValueTypeConverter, System::ComponentModel::TypeConverter ^ valueTypeConverter);
public virtual object ParseFormattedValue (object formattedValue, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.ComponentModel.TypeConverter formattedValueTypeConverter, System.ComponentModel.TypeConverter valueTypeConverter);
abstract member ParseFormattedValue : obj * System.Windows.Forms.DataGridViewCellStyle * System.ComponentModel.TypeConverter * System.ComponentModel.TypeConverter -> obj
override this.ParseFormattedValue : obj * System.Windows.Forms.DataGridViewCellStyle * System.ComponentModel.TypeConverter * System.ComponentModel.TypeConverter -> obj
Public Overridable Function ParseFormattedValue (formattedValue As Object, cellStyle As DataGridViewCellStyle, formattedValueTypeConverter As TypeConverter, valueTypeConverter As TypeConverter) As Object



单元格的显示值。The display value of the cell.


对单元格有效的 DataGridViewCellStyleThe DataGridViewCellStyle in effect for the cell.


显示值类型的 TypeConverter;如果使用默认转换器,则为 nullA TypeConverter for the display value type, or null to use the default converter.


单元格值类型的 TypeConverter;若要使用默认转换器,则为 nullA TypeConverter for the cell value type, or null to use the default converter.



单元格值。The cell value.


cellStylenullcellStyle is null.

FormattedValueType 属性值为 nullThe FormattedValueType property value is null.

-或--or- ValueType 属性值为 nullThe ValueType property value is null.

-或--or- 无法转换 formattedValueformattedValue cannot be converted.

formattedValuenullformattedValue is null.

- 或 --or- formattedValue 的类型与 FormattedValueType 属性指示的类型不匹配。The type of formattedValue does not match the type indicated by the FormattedValueType property.


当用户编辑单元格值并提交更改时, DataGridView 控件将调用此方法以将显示的值从转换 FormattedValueTypeValueTypeWhen the user edits a cell value and commits the change, the DataGridView control calls this method to convert the displayed value from the FormattedValueType to the ValueType. 然后,该控件将基础单元值或数据源值设置为转换后的值。The control then sets the underlying cell value or data source value to the converted value.

此方法的默认实现 formattedValue 使用 NullValue DataSourceNullValue FormatProvider 参数指示的单元格样式的、和属性分析参数 cellStyleThe default implementation of this method parses the formattedValue parameter using the NullValue, DataSourceNullValue, and FormatProvider properties of the cell style indicated by the cellStyle parameter.

如果 formattedValue 等于,则 NullValue 此方法将返回属性的值 DataSourceNullValue ; null 如果 DataSourceNullValueDBNull.Value ,则该单元格 ValueType 为引用类型。If formattedValue is equal to NullValue, this method returns the value of the DataSourceNullValue property or null if DataSourceNullValue is DBNull.Value and the cell ValueType is a reference type.

如果不 formattedValue 等于,则 NullValue 此方法 formattedValue 使用 FormatProvider 属性和指定的或默认的转换器进行分析。If formattedValue is not equal to NullValue, this method parses formattedValue using the FormatProvider property and the specified or default converters.

如果该单元格 ValueType 可为 null,则此方法将返回值包装为 Nullable<T> 类型。If the cell ValueType is nullable, this method wraps the return value as a Nullable<T> type.