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
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
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With