0
votes

I have a DataGridView control with MultSelect set to True and SelectionMode set to FullRowSelect. My goal is to iterate over all selected rows and then iterate over all cells in each row to get their value in string.

What I already figured now is how to get and iterate over all selected rows with the example code from this link (https://msdn.microsoft.com/en-us/library/x8x9zk5a(v=vs.110).aspx) but for the second problem, I'm still unable to figure out how to iterate over cells in each of the selected row

Any idea how to do that?

1

1 Answers

2
votes

You just need to iterate through each cell in the row with another nested for each...similar to how you're iterating through the selected rows. For example:

    For Each dgvr As DataGridViewRow In DataGridView1.SelectedRows
        For Each dgvc As DataGridViewCell In dgvr.Cells
            'do stuff to each cell
        Next
    Next