只需拨打这提高了DataGridView.CellFormatting事件FormattedValueType属性,然后更改单元格样式中的事件代码。
FormattedValue只是Value属性的格式化表示。 FormattedValue表示由FormattedValueType属性指定。
如果更改FormattedValueType属性,它将更改呈现给用户的方式而不更改该值。 =)
从MSDN这些话告诉你如何编辑FormattedValue的:
Value属性是由细胞包含实际数据对象, 而FormattedValue的是这个 对象的格式化表示。 ValueType和FormattedValueType属性分别对应于这些值的数据类型 。
获取该属性的值调用GetFormattedValue方法 到单元格的值转换成由FormattedValueType属性指示的类型 的等效显示值。这会引发 DataGridView.CellFormatting事件,您可以处理该事件以自定义 的值转换。
参阅MSDN上的讲话为DataGridViewCell.FormattedValue物业here.
当CellFormatting事件引发的,你可以做这样的事情:
Private Sub dgvMyData_CellFormatting(sender As System.Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgvMyData.CellFormatting
Dim MyStyle As New System.Windows.Forms.DataGridViewCellStyle
MyStyle.Format = "00 ct"
'or to remove the formatting:
MyStyle.Format = "00"
e.CellStyle = MyStyle
End Sub
我也有类似的问题,检查此[链接](http://stackoverflow.com/questions/25761275/datagridview-show-date-or-time-vb-net) – 2014-09-25 09:18:37
谢谢你的建议,我测试了** CellFormatting **事件,但是这个事件被解雇了当从数据库填入数据或输入到单元格时。它与value/string没有任何关系,双击时出现在editingMode中。 – 2014-09-25 12:07:34