DataGridView KeyDown事件

时间:2012-06-27 03:34:39

标签: vb.net datagridview event-handling

当你在EditMode中时,你能弄清楚DataGridView的问题是什么吗?

当我按Enter键时,它不会转到DatagridView_Keydown但是当我按两次Enter键时它会起作用。我的目标是按Enter键一次执行produre。

这是我的代码:

Private Sub DatagridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView.KeyDown
    If e.KeyCode = Keys.Enter Then
        'Do Procedures
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

选中此post,它已使用Tab键解决了我的问题。

Public Class DataGridViewEx
  Inherits DataGridView

  Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
    If keyData = Keys.Enter then
      Me.ProcessDownKey(keyData)
      Return True
    End If
    Return MyBase.ProcessCmdKey(msg, keyData)
  End Function
End Class

我刚刚将Keys.Tab修改为Keys.Enter