我有一个名为DataGridView1的数据网格,列A包含一个名称,列B包含一个文件的路径.如何为每一行运行一些代码?以这种方式遍历数据网格的正确术语是什么?
我需要的例子:
For each row in DataGridView1
MessageBox.Show DataGridView1.ColumnA.text & "," & DataGridView1.ColumnB.text
Run Code Online (Sandbox Code Playgroud)
谢谢
Pat*_*ald 14
你几乎就在那里,你需要以下内容:
For Each row As DataGridViewRow In DataGridView1.Rows
If Not row.IsNewRow Then
MessageBox.Show(row.Cells(0).Value.ToString & "," & row.Cells(1).Value.ToString)
End If
Next
Run Code Online (Sandbox Code Playgroud)
编辑:
如果DataGridView允许添加行,则需要检查row.IsNewRow是否为True.