Visual Basic; How to read each row in a datagrid?

I have a datagrid called DataGridView1, column A contains the name, column B contains the path to the file. How to run code for each line? What is the correct terminology for moving data along this path?

An example of what I need:

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

thanks

+4
source share
1 answer

You were almost 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 row.IsNewRow is not valid if your DataGridView allows you to add rows.

+12
source

Source: https://habr.com/ru/post/1286616/


All Articles