Hi,
I have a grid containing some static fields as well as some editable fields. My requirement is when I place cursor in any one of cell and press 'Enter' key control should transfer to next editable cell, similarly when I place control on last cell of a row and press 'Enter' key control should be in first editable cell of next row. How can I achieve it?
Thanks
-Kesav
HA
haneefm
Syncfusion Team
May 9, 2007 03:03 PM UTC
Hi Kesav,
By setting the WrapCellBehavior property to WrapRow, you can make the currentcell move to the first column of the next row when the currentcell is in last column. Below is a code snippet
this.grid.Model.Options.WrapCellBehavior = GridWrapCellBehavior.WrapRow;
Best Regards,
Haneef
KE
kesav
May 10, 2007 05:18 AM UTC
Hi Haneef,
The code snippet sent by you working fine to move control to the next row. But our requirement is, when 'Enter' key is pressed the control should move to the first 'editable' cell in the next row. Currently the control is moving to the first cell of next row irrespective of its celltype.
Similarly if the control is placed in a cell(not in the last cell of a row) when 'Enter' key is pressed control should move to next 'editable' cell. How can I achieve it?
Thanks
-Kesav
HA
haneefm
Syncfusion Team
May 10, 2007 07:57 PM UTC
Hi Kesav,
This behavior is by design. But you can change it by handling the QueryNextCurrentCellPosition. Here is a code snippet that shows you "How to navigate only editable cells in a Grid?".
private void gridControl1_QueryNextCurrentCellPosition(object sender, GridQueryNextCurrentCellPositionEventArgs e)
{
if( e.Direction == GridDirectionType.Right )
{
GridControl grid = sender as GridControl;
GridCurrentCell cc = grid.CurrentCell;
e.Handled = grid.Model[e.RowIndex,e.ColIndex].ReadOnly;
if( e.Handled )
{
cc.MoveTo(e.RowIndex,e.ColIndex + 1);
cc.ScrollInView();
}
}
}
Best regards,
Haneef
KE
kesav
May 12, 2007 05:55 AM UTC
Hi Haneef,
The code snippet sent by you works fine to traverse through the grid when 'Enter' is clicked. But it also changed the 'Tab' button behaviour. When 'Tab' button is clicked I want the same old behaviour which traverse through each and every cell (including static cells). How can I achieve it?
Thanks
-Kesav
HA
haneefm
Syncfusion Team
May 14, 2007 09:37 PM UTC
Hi kesav,
You can get the Enter key using the CurrentCellKeyDown event and then check that Enter key in a QueryNextCurrentCellPosition event for keeping the Tab Key behavior in a Grid. Below is a code snippet that show this.
private bool IsEnterKeyPressed = true;
private void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
if( e.KeyData == Keys.Enter )
IsEnterKeyPressed = true;
else
IsEnterKeyPressed = false;
}
private void gridControl1_QueryNextCurrentCellPosition(object sender, GridQueryNextCurrentCellPositionEventArgs e)
{
if( IsEnterKeyPressed && e.Direction == GridDirectionType.Right )
{
GridControl grid = sender as GridControl;
GridCurrentCell cc = grid.CurrentCell;
e.Handled = grid.Model[e.RowIndex,e.ColIndex].ReadOnly;
if( e.Handled )
{
cc.MoveTo(e.RowIndex,e.ColIndex + 1);
cc.ScrollInView();
}
}
}
Best regards,
Haneef