Click here to Skip to main content
15,907,236 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all,

I have a DataGridView, when pressing Enter button I want to change selection to another cell,

I used the Key_Down event handler but it didn't work when pressing Enter when the cell is in edit mode.

Thanks in advance,
:)
Posted
Updated 2-Mar-11 22:18pm
v2

1 solution

Use the DataGridView.CurrentCell property: MSDN[^]

int row = dataGridView1.CurrentCell.RowIndex;
int col = dataGridView1.CurrentCell.ColumnIndex;
dataGridView1.CurrentCell = dataGridView1[col, row + 1];
(You will have to add error checking and so forth, but that's the general way to do it.)
 
Share this answer
 
Comments
Michael Waguih 3-Mar-11 4:35am    
Thank you but how can I do it when pressing enter when editing the cell ?
OriginalGriff 3-Mar-11 4:40am    
Try the KeyPress event.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900