我有这样的DatagridView1
------------------
| Name | Phone |
| john | 0000 |
| joe | 1111 |
------------------
我的代码是:
For Each row As DataGridViewRow In DataGridView1.Rows
MsgBox(row.Cells(1).Value)
Next
此代码msgBox
生成具有数据0000 in 1st msgBox
和 1111 in 2nd msgBox
但我想要与此完全相反,即:
1111 in 1st msgBox
和0000 in 2nd msgBox
我应该为此做些什么?
您可以使用
带有Step -1
的For
循环来执行此操作:
For i As Integer = DataGridView1.Rows.Count - 1 To 0 Step -1
MsgBox(DataGridView1.Rows(i).Cells(1).Value)
Next
如果您更喜欢使用 For Each
循环,那么这也应该有效:
For Each row As DataGridViewRow In DataGridView1.Rows.Cast(Of DataGridViewRow).Reverse
MsgBox(row.Cells(1).Value)
Next