5

我正在尝试根据我在 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
4

4 回答 4

10

感谢@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
于 2013-06-18T13:43:22.097 回答
6

DGV.CurrentRow.Index

即使会工作selectionMode = CellSelect

于 2013-11-23T16:49:17.163 回答
3

我不认为我理解这个问题。为什么

iRowIndex = grdTransaction.SelectedRow.RowIndex

不行?

于 2013-06-18T13:39:08.847 回答
0

你可以试试这个..

Dim iRowIndex As Integer
Dim s As String

For i as Integer = 0 To Me.grdTransaction.SelectedCells.Count -1

     iRowIndex = Me.grdTransaction.SelectedCells.Item(i).RowIndex.ToString()
     aList.Add(Me.grdTransaction.SelectedRows(i).Cells("DataGridViewTextBoxColumn6").Value)

     MsgBox("Row index " & format(iRowIndex))
Next
于 2013-06-18T13:26:56.643 回答