We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Tab key after cell edit

Hello,

I'm trying to get the tab key to behave like the enter key after an edit in a cell.

The enter key works just fine, and there's even the property that lets me decide if I want to go to the next cell to the right or the next cell down after I click enter. I like that behavior, and that's what I want the tab key to do.

Currently if I hit the tab key after an edit, nothing seems to happen, but the cell validating event fires. Then if I hit the tab key again focus moved to the next cell.

I want to configure it so that I only have to hit the tab key once for the grid to validate the new cell value and move the current cell one to the right.

Any advice would be appreciated.

C

5 Replies

HA haneefm Syncfusion Team May 9, 2007 08:17 PM UTC

Hi Chris,

Try handling the TableControlCurrentCellKeyDown event and set e.Handled = true when the current cell text is changed. Here is a code snippet to show this.

private void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
if( e.KeyData == Keys.Tab )
{
GridControl grid = sender as GridControl;
GridCurrentCell cc = grid.CurrentCell;
e.Handled = cc.IsModified;
if( e.Handled )
cc.EndEdit();
}
}

Best regards,
Haneef


CH Chris May 9, 2007 08:26 PM UTC

Hey, that's getting much closer! Now when I click the tab key the change gets validated and the current cell moves, but it moves down.

Where can I tell the grid to move to the right after clicking the tab key?

Thanks again, Haneef. You're a champ!

C

>Hi Chris,

Try handling the TableControlCurrentCellKeyDown event and set e.Handled = true when the current cell text is changed. Here is a code snippet to show this.

private void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
if( e.KeyData == Keys.Tab )
{
GridControl grid = sender as GridControl;
GridCurrentCell cc = grid.CurrentCell;
e.Handled = cc.IsModified;
if( e.Handled )
cc.EndEdit();
}
}

Best regards,
Haneef


HA haneefm Syncfusion Team May 9, 2007 08:51 PM UTC

Hi Chris,

Please try this code in CurrentCellKeyDown event for TAB key in a grid.

private void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
if( e.KeyData == Keys.Tab )
{
GridControl grid = sender as GridControl;
GridCurrentCell cc = grid.CurrentCell;
e.Handled = true;
if( cc.IsModified )
cc.EndEdit();
else
cc.MoveRight(1);
}
}


Best regards,
Haneef

Note :
For downward direction then use CurrentCell.MoveDown method.
For upward direction then use CurrentCell.MoveUp method.
For left direction then use CurrentCell.MoveLeft method.
For required position then use CurrentCell.MoveTo method.


CH Chris May 10, 2007 02:11 PM UTC

Thanks Haneef, that helps a lot. But I'm running into a new problem.

If I edit a cell with celltype = checkbox I get this error: "An unhandled exception of type 'System.Exception' occurred in syncfusion.grid.windows.dll"

the code seems to work fine with string, datetime and double cells.


HA haneefm Syncfusion Team May 10, 2007 06:05 PM UTC

Hi Chris,

You can try checking the CellType in a CurrentCellKeyDown event and let me know if this helps.

GridControl grid = sender as GridControl;
GridCurrentCell cc = grid.CurrentCell;

if( cc.Renderer.CurrentStyle.CellType == GridCellTypeName.CheckBox
&& e.KeyData == Keys.Tab )
{
e.Handled = true;
if( cc.IsModified )
cc.EndEdit();
else
cc.MoveRight(1);
}

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon