Datagridview 值类型 属性 未更改
Datagridview valuetype property not changing
我有一些代码可以将 datagridview 的某些列的数据类型转换为双精度值,因为它们应该在我的网格视图中显示为货币。
但是,当我 运行 代码时,这些值仍显示为正常的小数。我是在使用错误的代码来做我想做的事情,还是根本无法完成?我很感激你能给我的任何帮助。
这是我的代码:
For i = 0 To ds.Tables(0).Columns.Count -1
InventoryDataGridView.ColumnCount = ds.Tables(0).Columns.Count
InventoryDataGridView.Columns(1).ValueType = GetType(Date) 'this type changes
InventoryDataGridView.Columns(2).ValueType = GetType(Double) 'this line and the line below do not occur in the grid view
InventoryDataGridView.Columns(4).ValueType = GetType(Double)
InventoryDataGridView.Columns(i).Name = InventoryColumns(i)
Next
使用 CellFormatting 事件显示您的货币:
Private Sub InventoryDataGridView_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles InventoryDataGridView.CellFormatting
If (e.ColumnIndex = 2) Then
e.Value = String.Format("{0:[=10=].00}", e.Value)
e.FormattingApplied = True
End If
End Sub
我有一些代码可以将 datagridview 的某些列的数据类型转换为双精度值,因为它们应该在我的网格视图中显示为货币。 但是,当我 运行 代码时,这些值仍显示为正常的小数。我是在使用错误的代码来做我想做的事情,还是根本无法完成?我很感激你能给我的任何帮助。 这是我的代码:
For i = 0 To ds.Tables(0).Columns.Count -1
InventoryDataGridView.ColumnCount = ds.Tables(0).Columns.Count
InventoryDataGridView.Columns(1).ValueType = GetType(Date) 'this type changes
InventoryDataGridView.Columns(2).ValueType = GetType(Double) 'this line and the line below do not occur in the grid view
InventoryDataGridView.Columns(4).ValueType = GetType(Double)
InventoryDataGridView.Columns(i).Name = InventoryColumns(i)
Next
使用 CellFormatting 事件显示您的货币:
Private Sub InventoryDataGridView_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles InventoryDataGridView.CellFormatting
If (e.ColumnIndex = 2) Then
e.Value = String.Format("{0:[=10=].00}", e.Value)
e.FormattingApplied = True
End If
End Sub