Visual Basic, How do I read each row in a datagrid?

此生再无相见时 提交于 2019-12-30 10:00:55

问题


I have a datagrid called DataGridView1, column A contains a name, column B contains a path to a file. How do I run some code for each row? What is the correct terminology for traversing a datagrid in this way?

Example of what I need:

For each row in DataGridView1
 MessageBox.Show DataGridView1.ColumnA.text & "," & DataGridView1.ColumnB.text

Thanks


回答1:


You were nearly there, you need something like the following:

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

EDIT:

You need to check if the row.IsNewRow is not True if your DataGridView allows adding rows.



来源:https://stackoverflow.com/questions/1031704/visual-basic-how-do-i-read-each-row-in-a-datagrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!