Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataGridView Multiple Row Selection Issue

I am trying to check for multiple selections in a DataGridView with a For... Next Loop, but even though I have selected multiple rows, the only row with the property Selected=True is the first row in the selection. Is there a way around this?

MultiSelect is true on the DataGridView.

My code is as follows:

For Each dr As DataGridViewRow In dgv.Rows
    If dr.Selected = True Then
        intSelectedRow = dr.Index
        SetTime("KeyEntry", dgv.Name, intSelectedRow)
    End If
Next

Thanks

like image 608
J2Tuner Avatar asked Jan 28 '13 14:01

J2Tuner


1 Answers

Try this:

Dim selectedItems As DataGridViewSelectedRowCollection = dgv.SelectedRows
      For Each selectedItem As DataGridViewRow In selectedItems
            'Add code to handle whatever you want for each row
      Next
End Sub
like image 135
Nianios Avatar answered Sep 29 '22 12:09

Nianios