根据DataGridView上的选定单元格获取RowIndex

alw*_*NET 5 vb.net datagridview visual-studio-2010

我正在尝试根据DataGridView上的选定单元格获取行索引.我怎么能在VB.NET中做到这一点?

这就是我所拥有的:

 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
Run Code Online (Sandbox Code Playgroud)

alw*_*NET 8

感谢@matzone我已经弄明白了:

  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
Run Code Online (Sandbox Code Playgroud)


小智 6

DGV.CurrentRow.Index

即使会工作 selectionMode = CellSelect