Windows Dev Center

datagridview enter key move right


  • Hi,

        I want the cursor to move right by one cell when Enter key is pressed at a cell in the DataGridView.  By default the cursor goes down by one cell.  Please help.


    Cris Evan


    Monday, September 27, 2010 12:57 PM


All replies


    There's a TAB key for this behavior. You should not try to change common conventions in general.

    Anyway, if you must, you could do something like this :

                if (e.KeyCode == Keys.Enter)
                    e.Handled = true;

    in keydown event of datagridview.



    Quizwith.NET is now open for everyone !

    Living on Earth may be expensive, but did you know that it includes a free trip around the sun? Isn't that worth it?
    Monday, September 27, 2010 1:10 PM
  • Hi,

        Sorry to get back to you people late.  Because I was comfortable with the code given by Omie.  When the cell is in edit mode it still goes down instead of moving right.  I checked the code, control doesn't go to the KeyDown event of the GridView when Enter key is pressed in edit mode.  So I tried using the following code after seeing it from another forumn post.

    public class DataGridViewNew : DataGridView
            protected override bool ProcessDialogKey(Keys keyData)
                Keys key = (keyData & Keys.KeyCode);
                if (key == Keys.Enter)
                    return this.ProcessRightKey(keyData);
                return base.ProcessDialogKey(keyData);
            protected override bool ProcessDataGridViewKey(KeyEventArgs e)
                if (e.KeyCode == Keys.Enter)
                    return this.ProcessRightKey(e.KeyData);
                return base.ProcessDataGridViewKey(e);

    Here the above mentioned problem is solved, but control doesn't go to the beginning of the next row when Enter key is pressed at the end of the previous row.  Please help.

    Cris Evan



    Monday, October 04, 2010 12:30 PM
  • Hi evan,

    Have you checked your another thread talking about the same question that move to next cell in DataGridView by Pressing Enter:, I have reply this question there.

    And the other your same topic question:


    "DataGridView KeyDown in Editmode" is a hot topic if you google this question you will get a lot of links that gives a right anwser.0
    DataGridView - KeyDown in EditMode:

    DataGridView limit entry of only digits see the last reply of me.

    Best wishes,
    Helen Zhou

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked as answer by Helen Zhou Monday, October 11, 2010 1:29 AM
    Tuesday, October 05, 2010 7:43 AM