Link to home
Start Free TrialLog in
Avatar of mystar
mystar

asked on

Send "Tab" key in datagrid when press "Enter" Key.

hello.
Many applications that display data in a grid interface allow the user to use the ENTER (RETURN) key to navigate from cell to cell.
I want when I press Enter key the next cell of DataGrid  be selected. for first time this is done with follow code but for second time the focus go to the last cell of datagrid.


protected override bool ProcessCmdKey(ref Message msg, Keys keydata)
{

if(keydata == Keys.Enter)
{
 SendKeys.Send("{Tab}");
 return false;
}
base.ProcessCmdKey(ref msg, keydata);

}
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You should change your code a little bit:

protected override bool ProcessCmdKey(ref Message msg, Keys keydata)
{

if(keydata == Keys.Enter)
{
 SendKeys.Send("{Tab}");
 return true;
}
return base.ProcessCmdKey(ref msg, keydata);

}
My recommandation: points to emoreau (the comment from TheAvenger is very near to the code of link I did provide).