datagridview enter key move right
-
Monday, September 27, 2010 12:57 PM
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
All Replies
-
Monday, September 27, 2010 1:10 PM
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;
SendKeys.Send("{TAB}");
}in keydown event of datagridview.
Thanks
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, October 04, 2010 12:30 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
cris -
Tuesday, October 05, 2010 7:43 AMModerator
Hi evan,
Have you checked your another thread talking about the same question that move to next cell in DataGridView by Pressing Enter
:
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/11bb0ed2-23ed-4e7c-8815-174a98889d72, I have reply this question there.And the other your same topic question: http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/5c1ab497-4595-44f6-9662-59a5feb319c5/
"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
:
http://social.msdn.microsoft.com/Forums/en/winformsdatacontrols/thread/575dfd63-846e-4bad-93ed-2c3e1eeadc1b
DataGridView limit entry of only digits
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/11bb0ed2-23ed-4e7c-8815-174a98889d72 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 ZhouModerator Monday, October 11, 2010 1:29 AM


