Sunday, April 10, 2011

Tab key work as an Enter key in Datagridview

To make the Tab key work as Enter key, we have to inherit DataGridView controls and override two methods ProcessDataGridViewKey and ProcessDialogKey. In both the methods if the user has click Tab then we have to ProcessEnterKey of Datagridview.

Public Class NewDataGridView
Inherits DataGridView

Protected Overrides Function ProcessDataGridViewKey(ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean
If e.KeyCode = Keys.Tab Then
Me.ProcessEnterKey(e.KeyData)
Return True
End If
Return MyBase.ProcessDataGridViewKey(e)
End Function

Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Tab Then
Me.ProcessEnterKey(keyData)
Return True
End If
Return MyBase.ProcessDialogKey(keyData)
End Function
End Class

No comments:

Post a Comment