I’m looping through rows in a datagridview, and selecting a cell from the 3rd column each time:
Dim customer_name as String
For Each dgvr As DataGridViewRow In myDataGridView.Rows
customer_name= dgvr.Cells(2).Value
'....
next dgvr
However, I’d really like to make it dynamic, in case a new column gets added to the grid, so that I need the 4th column, not the 3rd.
Ideally I’d like to use the column’s header text. So something like…
customer_name= dgvr.Cells("Customer").value
Can this be done?
This can be done, it is possible to select by header text. You can loop through each row and find the value for the name of a column.
This should set the value of the test string to the current cell under the column name.
Hope this helps 🙂