I'm trying to get the row indices based on my selected cells on a DataGridView. How can I do that in VB.NET?
This is what I have:
Dim iRowIndex As Integer
For i = 0 To Me.grdTransaction.SelectedCells.Item(iRowIndex)
iRowIndex = Me.grdTransaction.SelectedCells.Item(i).RowIndex.ToString()
Dim s As String = Me.grdTransaction.SelectedRows(i).Cells("DataGridViewTextBoxColumn6").Value
aList.Add(s)
MsgBox("Row index " & iRowIndex)
Next
To get the selected cells in a DataGridView controlUse the SelectedCells property.
Thanks to @matzone I have figured it out:
Dim iRowIndex As Integer
For i As Integer = 0 To Me.grdTransaction.SelectedCells.Count - 1
iRowIndex = Me.grdTransaction.SelectedCells.Item(i).RowIndex
aList.Add(Me.grdTransaction.Rows(iRowIndex).Cells("DataGridViewTextBoxColumn6").Value)
MsgBox("Row index " & Format(iRowIndex))
Next
DGV.CurrentRow.Index
Will work even if selectionMode = CellSelect
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