The DataGridView is a terrific control built into .NET that provides a customizable table for entering and displaying data. If you provide the DataGridView in your software as a means for the user to enter multiple rows of data, you may wish to redefine the default behavior of the Enter key.
By default, when you press the Enter key in the DataGridView, the cursor moves to the cell in the same column immediately below the current cell (red arrow in the image below). But when entering multiple rows of data, a better response from the Enter key would be to move the cursor to the first cell in the next row (blue arrow).

To do this, you can derive a new class from the DataGridView:
public class Grid : DataGridView {
Then override the OnKeyUp protected method as follows:
protected override void OnKeyUp( KeyEventArgs e ) { if (e.KeyCode == Keys.Enter) { int currentRow = this.CurrentRow.Index; if (currentRow >= 0) this.CurrentCell = this.Rows[currentRow].Cells[0]; } base.OnKeyUp( e ); }
Of course, if you wish to provide this capability for an existing DataGridView, you can simply subscribe to the KeyUp event and execute the same code above in the event handler.
Popularity: 20% [?]
Related posts:

i have search this solution couple of hours. Am really happy to find this solution. thanks
me too
thanx for the above mentioned code,
but just being a new programmer,
please clearify my doubt :
even if i derive a new class grid,
how can we use that class in our code,
what i mean is datagridview is a control,so
dont we have to work with the same object,say dtg1 ?
and when we will press enter key in dtg1,how overriden method from grid class will get called??
i know i might be asking a childish one,
but just want to clear my concept,please reply
Swaroop, there are two ways to use a derived DataGridView control:
1. You can add your derived DataGridView to the Toolbox, then drag and drop your derived object onto your Design view.
2. You can edit the designer-generated code directly and replace the DataGridView class name with your derived class name. Note that this must be done in two places: the object definition, and the statement that creates the object.