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

定义

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

public:
 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

参数

formattedValue
Object

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

cellStyle
DataGridViewCellStyle

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

formattedValueTypeConverter
TypeConverter

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

valueTypeConverter
TypeConverter

单元格值类型的 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 控件将调用此方法以将显示的值从 FormattedValueType 转换为 ValueTypeWhen 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.

此方法的默认实现使用由 cellStyle 参数指示的单元格样式的 NullValueDataSourceNullValueFormatProvider 属性分析 formattedValue 参数。The 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 属性的值; 如果 DataSourceNullValueDBNull.Value,则返回 null,并且单元 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,则此方法使用 FormatProvider 属性和指定的或默认的转换器分析 formattedValueIf 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.

适用于

另请参阅