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.

VB Code

Public Class NewDataGridView
Inherits DataGridViewProtected Overrides Function ProcessDataGridViewKey(ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean
If e.KeyCode = Keys.Tab Then
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
Return True
End If
Return MyBase.ProcessDialogKey(keyData)
End Function
End Class

C# Code
protected override bool ProcessDataGridViewKey(System.Windows.Forms.KeyEventArgs e)
if (e.KeyCode == Keys.Tab)
return base.ProcessDataGridViewKey(e);

protected override bool ProcessDialogKey(System.Windows.Forms.Keys keyData)
Keys key = (keyData & Keys.KeyCode);
if (key == Keys.Tab)
}return base.ProcessDialogKey(keyData);


About Asif
Hello Friends… I have done my Bachelor of Engineering in Information Technology from Gujarat University. I have 1.7 years experience of web and windows based application development.. My basic idea to start a blog is to store all important link which help me in my application and access to every where. Also this information is help others who want to makes their application powerful. I am interested in .net framework (1.0,2.0,3.0,3.5 and more). This blog contain also many information related to SQL, Custom Controls in Please share your ideas and any query if you have...

6 Responses to Tab key work as an Enter key in Datagridview

  1. Gicci says:

    I do not believe I have seen this described in such an informative way before. You really have clarified this for me. Thank you!

  2. kousik says:


    I want to focus a particular cell when press enter in that cell again press i need default behavior of enter kay.


    • Asif says:

      Hi Kousik.

      If you want to edit any cell in DataGridView then press F2.

      As per your information you want it on Enter key.
      when you set enter key as right then tough but you can check your cell in ProcessDialogKey like grdview.row[currentrow].cell[currentcell] and if match then simply return.

      This might help you.

  3. lakhan says:

    my complete problem is that…….
    i have one table sql2003..and columns like…..

    at page load event …
    code for binddata in data gridview..

    at run time it show me like

    setno date day
    1 31/4/2011 friday

    //31/4/2011 is last financial year date which already save in table

    now user edit this date enter another date which should be less than this date
    let he enter 1//1/2010 and press enter key
    at first enter prees datagridview should like this
    setno date day
    1 1/1/2010 Monday
    2 8/1/2010 Monday

    and now at 2nd time as he press enterkey gridview should like ..
    1 1/1/2010 Monday
    2 8/1/2010 Monday
    3 15/1/2010 Monday
    and so on …but not greater than financial year date

    i think now u can understand my problem ….if u can help me than please please help me …….

    thanks in both the cases
    😦 lakhan

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: