vb.net 根据 DataGridView 上的选定单元格获取 RowIndex
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17169628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting RowIndex based on the selected cells on a DataGridView
提问by alwaysVBNET
I'm trying to get the row indices based on my selected cells on a DataGridView. How can I do that in VB.NET?
我正在尝试根据我在 DataGridView 上选择的单元格获取行索引。我怎样才能在 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
回答by alwaysVBNET
Thanks to @matzone I have figured it out:
感谢@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
回答by user3025397
DGV.CurrentRow.Index
DGV.CurrentRow.Index
Will work even if selectionMode = CellSelect
即使会工作 selectionMode = CellSelect
回答by Philip Stratford
I don't think I'm understanding the question. Why does
我不认为我理解这个问题。为什么
iRowIndex = grdTransaction.SelectedRow.RowIndex
not work?
不行?
回答by matzone
You can try this ..
你可以试试这个..
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