Vb.net 基于DataGridGiew上的多个选定单元格获取RowIndex
我试图根据DataGridView上的多个选定单元格获取行索引。如何在VB.NET中实现这一点 这就是我所拥有的:Vb.net 基于DataGridGiew上的多个选定单元格获取RowIndex,vb.net,datagridview,Vb.net,Datagridview,我试图根据DataGridView上的多个选定单元格获取行索引。如何在VB.NET中实现这一点 这就是我所拥有的: If e.RowIndex >= 0 Then Dim row As DataGridViewRow row = Me.DataGridView1.Rows(e.RowIndex) sno.Text = row.Cells("F2").Value.ToString sname.Text = row.Cells("F3").Value.ToStr
If e.RowIndex >= 0 Then
Dim row As DataGridViewRow
row = Me.DataGridView1.Rows(e.RowIndex)
sno.Text = row.Cells("F2").Value.ToString
sname.Text = row.Cells("F3").Value.ToString
final.Text = row.Cells("F16").Value.ToString
End If
DatagridView具有SelectedCells属性和每个单元格上的行索引:
For Each c As DataGridViewCell In DataGridView1.SelectedCells
Debug.Print(c.RowIndex)
Next
您将获得每个选定单元格的命中率-可能具有重复的rRowIndex
您可以将SelectionMode设置为rows并使用SelectedRows
要将第一个选定单元格用作要使用的行,请执行以下操作:
If DataGridView1.SelectedCells.count > 0 Then
Dim row As DataGridViewRow
row = Me.DataGridView1.Rows(DataGridView1.SelectedCells(0).RowIndex)
sno.Text = row.Cells("F2").Value.ToString
sname.Text = row.Cells("F3").Value.ToString
final.Text = row.Cells("F16").Value.ToString
End If
第二个选项可能不起作用-我认为所选的。。。方法不能按定义的顺序返回单元格/行,即最后一个单元格可能是第0个单元格。