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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Tab key after cell edit

Thread ID:

Created:

Updated:

Platform:

Replies:

60660 May 9,2007 07:01 PM UTC May 10,2007 06:05 PM UTC WinForms 5
loading
Tags: GridControl
Chris
Asked On May 9, 2007 07:01 PM UTC

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

haneefm [Syncfusion]
Replied On 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

Chris
Replied On 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

haneefm [Syncfusion]
Replied On 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.

Chris
Replied On 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.

haneefm [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;