我有DataGridView
有5列。我使用For Next
循环来迭代每列的值,但由于某种原因,它仅适用于第1列和第2列。
这是我的代码:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As Decimal
Dim b As Decimal
Dim i As Integer
a = 5.23
For i = 0 To DataGridView1.Rows.Count - 1
b = a * (DataGridView1.Item(i, 0).Value)
MessageBox.Show(b)
Next
End Sub
答案 0 :(得分:1)
如果要迭代第一行的每一列,则需要循环到DataGridView.Columns.Count - 1
。
For i = 0 To DataGridView1.Columns.Count - 1