How to control datagridview cursor movement in c #

I would like my datagridview cursor to move directly to the next column instead of going to the next row after entering data into the cell.

I tried to take control of the cursor by capturing keys through the dataGridView1_KeyDown event, but this does not prevent the cursor from moving to the next row after entering data into the cell ...

Thanks in advance for your help.

Greetings

+4
source share
1 answer

Here is the answer from Mark Rideout (DatagridView Program Manager)

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=157055&SiteID=1

Scroll down 4 posts (and then more, because they make better versions later in the stream).

For future links, if the link expires ( All Mark Rideout Credits ):

Create a new class called dvg that inherits from DataGridView. Compile the project, and then use this advanced Datagridview-control instead of the usual one, and you will have a datagridview view that selects the following cell when you press enter:

public class dgv : 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); } 

}

+5
source

All Articles