我有一个DataGridView,我想用双精度值填充它。当值是字符串时,DataGridView填充得很好,但现在它在第一列中输出System.Double[],在任何其他列中都不输出任何内容。我知道转换是有效的,因为我可以将双精度值打印到控制台。如何以编程方式设置所有列的格式?(我不想使用设计器)
我的代码:
Dim cols() as String = {"col1", "col2", "col3"} ' this goes on for 33 cols
Dim currentRow As String()
Dim row() As Double
Dim c As Integer
DataGridView1.Rows.Clear()
DataGridView1.ReadOnly = True
DataGridView1.DefaultCellStyle.Format = "G"
DataGridView1.ColumnCount = 33
For c = 0 To (cols.Length - 1)
DataGridView1.Columns(c).Name = cols(c)
Next
While Not at EndOfFile ' This line and the next are semi-pseudocode, but it's the same idea
read/parse line into currentRow
Dim x As Integer
For x = 0 To (currentRow.Length - 1)
ReDim Preserve row(x)
Double.TryParse(currentRow(x), row(x))
Next
With Me.DataGridView1.Rows
.Add(row)
End With输出屏幕截图:

https://stackoverflow.com/questions/44660617
复制相似问题