在 VB.Net 中处理 DataGridView 中的索引?



我的DataGridView只有两行。我已经设置了AllowUserToAddNewRow = False.我正在从数据库中填充DataGridView行。我想通过按 Enter 键在事件KeyDown文本框中传输其值。当我按 输入DataGridView中的键选择第一行的内容时,DataGridView.CurrentRow.Index返回 1。以同样的方式,当我选择第二行并按 输入 键,然后这里也会发生同样的事情,这意味着它也返回DataGridView.CurrentRow.Index为 1。有什么概念可以让我处理这个问题吗?

我尝试过的:

RowIndx = Me.DataGridView1.CurrentRow.Index

你骗子只是这样做:

Private Sub DataGridView1_KeyDown(sender As Object, e As KeyEventArgs) Handles DataGridView1.KeyDown
If e.KeyCode = Keys.Enter Then
Dim RowIndx As Integer
RowIndx = DataGridView1.SelectedCells.Item(0).RowIndex
MsgBox(RowIndx)
End If
End Sub

希望它对:)有所帮助

最新更新