2012-06-27 163 views
1

您可以在EditMode中弄清楚DataGridView的問題是什麼?DataGridView KeyDown事件

當我按Enter鍵不會去DatagridView_Keydown,但當我按Enter鍵兩次它的工作。我的目標是按一次Enter鍵執行產品。

這裏是我的代碼:

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 
+0

您是否爲此檢查了「CellEndEdit」事件? – NeverHopeless

回答

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.TabKeys.Enter