我试图基于我在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

最佳答案

感谢@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

07-26 09:28