我的DataGridView
只有两行。我已设置AllowUserToAddNewRow = False
。我在数据库中填充DataGridView
中的行。我想通过按Enter键在KeyDown
事件的文本框中传输其值。当我按下DataGridView
中的Enter键以选择第一行的内容时,DataGridView.CurrentRow.Index
返回1.以同样的方式当我选择第二行并按Enter键时,同样发生在这里,意味着它也将DataGridView.CurrentRow.Index
返回为1.是否有任何概念可以解决这个问题?
我尝试过:
RowIndx = Me.DataGridView1.CurrentRow.Index
答案 0 :(得分:1)
You con do it simply like this :
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
Hope it helped :)