我正在尝试根据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
答案 0 :(得分: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
答案 1 :(得分:4)
DGV.CurrentRow.Index
即使selectionMode = CellSelect
答案 2 :(得分:3)
我认为我不理解这个问题。为什么
iRowIndex = grdTransaction.SelectedRow.RowIndex
不起作用?
答案 3 :(得分: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