using enter key tab to next row

If we press enter focus moves to next column and in last column on pressing enter focus moves to next row first column.

If we want using enter key to skip readonly columns .

Col1                          Col2                    Col3
Readonly False     Readonly True      ReadonlyFalse

On Pressing enter from col1 focus should be on col3.

And if Col 3 readonly also true then foucs should be in next row, first cell.

1 Reply

VS Vijayarasan Sivanandham Syncfusion Team April 21, 2022 10:56 AM UTC

Hi Luu Tan Phat,

Please find answer for your queries below

Queries

Solutions

 

If we press enter focus moves to next column

 

Your requirement to move focus to next column when pressing Enter key in GridGroupingControl can be achieved by setting GridDirectionType.Right for EnterKeyBehavior property in GridGroupingControl.Table.TableModel.Options.  Please refer the below code snippet,

//here change the enter key behavior
this.gridGroupingControl1.Table.TableModel.Options.EnterKeyBehavior = GridDirectionType.Right;

 

in last column on pressing enter focus moves to next row first column

 

Your requirement to move focus to the first column of the next row when pressing Enter key in last column in GridGroupingControl can be achieved by setting GridWrapCellBehavior.WrapRow for WrapCellBehavior property in GridGroupingControl.Table.TableModel.Options.  Please refer the below code snippet,

//here change the enter key behavior

this.gridGroupingControl1.Table.TableModel.Options.WrapCellBehavior = GridWrapCellBehavior.WrapRow;

 

If we want using enter key to skip readonly columns .

And if Col 3 readonly also true then foucs should be in next row, first cell.

 

Your requirement to skip read only columns when move focus to next column while pressing the Enter key in GridGroupingControl can be achieved by customize the TableControlCurrentCellKeyDown event in GridGroupingControl. Please refer the below code snippet,

this.gridGroupingControl1.TableControlCurrentCellKeyDown += OnTableControlCurrentCellKeyDown;

 

void OnTableControlCurrentCellKeyDown(object sender, GridTableControlKeyEventArgs e)

        {

            //her check the pressed key is Enter

            if (e.Inner.KeyCode == Keys.Enter)

            {

                //here move the current cell to next column based on readonly property in GridGroupingControl

                for (int I = e.TableControl.CurrentCell.ColIndex; I <= e.TableControl.TableDescriptor.GetLastColumnIndex(); i++)

                {

                    GridColumnDescriptor style = null;

                    //here check next column is last column or not

                    if (I != e.TableControl.TableDescriptor.GetLastColumnIndex())

                        style = e.TableControl.TableDescriptor.Columns[(e.TableControl.TableDescriptor.FieldToColIndex(i) – 1)];

                    else

                        style = e.TableControl.TableDescriptor.Columns[0];

 

                    if (style.ReadOnly)

                    {                       

                        if (I != e.TableControl.TableDescriptor.GetLastColumnIndex())

                            e.TableControl.CurrentCell.MoveTo(e.TableControl.CurrentCell.RowIndex, e.TableControl.TableDescriptor.FieldToColIndex(i));

                        else

                            e.TableControl.CurrentCell.MoveTo(e.TableControl.CurrentCell.RowIndex + 1, e.TableControl.TableDescriptor.FieldToColIndex(0));

 

                        break;

                    }

                    else

                        break;

                }

            }

 

        }


Please find the sample in the attachment and let us know if you have any concerns in this.

Regards,
Vijayarasan S


Attachment: GridGroupingControldemo_f63da406.zip

Loader.
Up arrow icon