Enter key behaves like Tab in datagridview in vb.net

Introduction
Most of the user use Enter key except Tab to move focus in the next controls because it is very faster to press Enter key instead of Tab key. But in .net the DataGridView works with Tab key to move focus in Next cell so we need to customize the datagridView and Overrides some function.

Add a new custom control in project and inherits it with System.Windows.Forms.DataGridView.

Code of Custom control:

Public Class CustomDataGridView
    Inherits DataGridView
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)
 
        'Add your custom paint code here
    End Sub
    Protected Overrides Function ProcessDataGridViewKey(ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean
        If e.KeyCode = System.Windows.Forms.Keys.Enter Then
            Me.ProcessTabKey(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 = System.Windows.Forms.Keys.Enter Then
            Me.ProcessTabKey(keyData)
            Return True
        End If
        Return MyBase.ProcessDialogKey(keyData)
    End Function
 
End Class

After that Build the application then you will find that there in a new control in your toolbox named as your custom control name(‘CustomDataGridView’ in above example).

You can easily use this with drag and drop and in this datagridview enter key works as a tab key.

Author: Ankur

Have worked primarily in the domain of Calling, CRM and direct advertisers services. My technological forte is Microsoft Technologies especially Dot Net (Visual Studio 2003, 2005, 2008, 2010 and 2012) and Microsoft SQL Server 2000,2005 and 2008 R2. My Area of Expertise is in C#. Net, VB.Net, MS-SQL Server, ASP. Net, Silverlight, HTML, XML, Crystal Report, Active Reports, Infragistics, Component Art, ComponeOne, Lead Tools etc.