Vb.net Visual Basic-输入以执行DataGridView CellContentClick

Vb.net Visual Basic-输入以执行DataGridView CellContentClick,vb.net,winforms,datagridview,basic,Vb.net,Winforms,Datagridview,Basic,首先,我想潜在地道歉,因为我是VisualBasic自学的新手,所以我的一些代码可能看起来很奇怪 我加载一个DataGridView,其中包含由SELECT语句填充的信息,当我单击视图中的某个单元格时,它会加载一个新表单,这很好。但是,我想知道是否有一种方法可以让我从单击更改为按ENTER键 我已经附上了我的代码,希望这能有所帮助 先谢谢你 Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Window

首先,我想潜在地道歉,因为我是VisualBasic自学的新手,所以我的一些代码可能看起来很奇怪

我加载一个DataGridView,其中包含由SELECT语句填充的信息,当我单击视图中的某个单元格时,它会加载一个新表单,这很好。但是,我想知道是否有一种方法可以让我从单击更改为按ENTER键

我已经附上了我的代码,希望这能有所帮助

先谢谢你

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    If e.KeyCode = Keys.Enter Then ' not sure on code here
End Sub

Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
    If Update_Detail.Visible = True Then Update_Detail.Close()
    Dim istat As Object
    If e.RowIndex > -1 Then istat = DataGridView1.Rows(e.RowIndex).Cells(0).Value
    If e.ColumnIndex < 1 And e.RowIndex > -1 Then Update_Detail.TextBox1.Text = istat
    If e.ColumnIndex < 1 And e.RowIndex > -1 Then Update_Detail.Show()
End Sub

另外,我正在将Visual Studio 2015与.Net Framework 4.5.2一起使用

如果您使用的是vb.Net,则无需同时包含VBA标记。谢谢-此标记已被删除。网格上有一个按键关闭事件。你可以用这个。嗨,这真是棒极了。不过还有一件事——当我按下enter键时,它也会保持向下移动到行的功能。你知道可以关闭这个吗?没问题。请参见此处了解潜在的解决方案。您可以尝试添加。e、 SupersKeyPress=最后为True。不过我还没试过。这又是一种享受。非常感谢你:祝你好运。几乎总是解决一切问题的办法o
  Private Sub DataGridView1_KeyDown(sender As Object, e As KeyEventArgs) Handles DataGridView1.KeyDown
        If e.KeyCode = Keys.Enter Then

            Dim currentRowIndex As Integer = DataGridView1.CurrentCell.RowIndex
            Dim currentColumnIndex As Integer = DataGridView1.CurrentCell.ColumnIndex


            Dim istat As Object

            If currentRowIndex > -1 Then istat = DataGridView1.Rows(currentRowIndex).Cells(0).Value
            If currentColumnIndex < 1 And currentRowIndex > -1 Then Update_Detail.TextBox1.Text = istat
            If currentColumnIndex < 1 And currentRowIndex > -1 Then Update_Detail.Show()

        End If

    End Sub