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

Got to new bottom left of new row on enter

I have a GGC with the ability to add new records at the bottom of the grid. How do I get the control to move the cell focus to the first column of the newly added row when the user presses enter? I've tried some of the examples that demonstrate moving, but can't find any combination that moves the focus to the first column of the new row.


10 Replies

HA haneefm Syncfusion Team May 29, 2007 07:12 PM UTC

Hi Tod,

By default, when a record is added through AddNewRow and when the enter key is pressed, the current record will be the newly added row. But you can stop the navigation by handling the CurrentRecordContextChange event and set the e.Cancel to true for CurrentRecordAction.LeaveRecordCalled. Here is a code snippet

private void gridGroupingControl1_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e)
{
if( e.Action == CurrentRecordAction.LeaveRecordCalled)
{
if(e.Record.Kind == DisplayElementKind.AddNewRecord && IsEnterPressed)
e.Cancel = true;
}
}

Best regards,
Haneef


TG Tod Golding May 29, 2007 08:07 PM UTC

Thanks for the quick reply. I think my request wasn't quite clear, though. I don't want to cancel the behavior of the enter key. I just want to control where the focus moves after pressing enter.

When the user presses enter on the current row, I want the system to add a new row *and* move the focus to the cell that is the first column of the newly added row.


>Hi Tod,

By default, when a record is added through AddNewRow and when the enter key is pressed, the current record will be the newly added row. But you can stop the navigation by handling the CurrentRecordContextChange event and set the e.Cancel to true for CurrentRecordAction.LeaveRecordCalled. Here is a code snippet

private void gridGroupingControl1_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e)
{
if( e.Action == CurrentRecordAction.LeaveRecordCalled)
{
if(e.Record.Kind == DisplayElementKind.AddNewRecord && IsEnterPressed)
e.Cancel = true;
}
}

Best regards,
Haneef


HA haneefm Syncfusion Team May 29, 2007 11:42 PM UTC

Hi Tod,

You can handle the TableControlCurrentCellKeyUp event to control the EnterKey movement in a grid. Here is a code snippet to show this.

private bool IsAddNew = false;
private void gridGroupingControl1_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e)
{
if( e.Action == CurrentRecordAction.LeaveRecordCalled && e.Record.Kind == DisplayElementKind.AddNewRecord)
IsAddNew = true;
}
private void gridGroupingControl1_TableControlCurrentCellKeyUp(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlKeyEventArgs e)
{
if( e.Inner.KeyData == Keys.Enter && IsAddNew )
e.TableControl.Table.CurrentRecord.SetCurrent("FirstColumnName");
}

Best regards,
Haneef


TG Tod Golding May 31, 2007 05:19 PM UTC

Thanks. This almost works. I'm adding new rows to the *bottom* of my grid. When enter is pressed, the next "new row" is added to the bottom (which is what I want). However, I also want the focus to move to the first of of this newly added row (the last row in the grid). This solution moves me to the first column of the *current* row. Is there a way to move to the newly added row instead?

>Hi Tod,

You can handle the TableControlCurrentCellKeyUp event to control the EnterKey movement in a grid. Here is a code snippet to show this.

private bool IsAddNew = false;
private void gridGroupingControl1_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e)
{
if( e.Action == CurrentRecordAction.LeaveRecordCalled && e.Record.Kind == DisplayElementKind.AddNewRecord)
IsAddNew = true;
}
private void gridGroupingControl1_TableControlCurrentCellKeyUp(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlKeyEventArgs e)
{
if( e.Inner.KeyData == Keys.Enter && IsAddNew )
e.TableControl.Table.CurrentRecord.SetCurrent("FirstColumnName");
}

Best regards,
Haneef


HA haneefm Syncfusion Team May 31, 2007 09:34 PM UTC

Hi Tod,

I have tested the attached sample to reproduce this issue, but could not get this. Maybe I am not adopting the steps that you are doing. kindly provide me a small sample to reproduce the issue or modify attached sample accordingly. This will help me to analyze the issue further.

Here is a sample.
http://websamples.syncfusion.com/samples/Grid.Windows/GoToNewlyAddedRowFirstColumn/main.htm

Best regards,
Haneef


TG Tod Golding May 31, 2007 10:03 PM UTC

Your example adds new items at the top of the grid. For my case, I'm trying to add them at the *bottom* of the grid.

Just change the config of your grid to use the following two options and you will see the problem:
this.gridGroupingControl1.TopLevelGroupOptions.ShowAddNewRecordAfterDetails = true;
this.gridGroupingControl1.TopLevelGroupOptions.ShowAddNewRecordBeforeDetails = false;



>Hi Tod,

I have tested the attached sample to reproduce this issue, but could not get this. Maybe I am not adopting the steps that you are doing. kindly provide me a small sample to reproduce the issue or modify attached sample accordingly. This will help me to analyze the issue further.

Here is a sample.
http://websamples.syncfusion.com/samples/Grid.Windows/GoToNewlyAddedRowFirstColumn/main.htm

Best regards,
Haneef


HA haneefm Syncfusion Team June 1, 2007 08:37 PM UTC

Hi Tod,

In your TableControlCurrentCellKeyUp event, if e.Inner.KeyData is equals to Keys.Enter, then try calling the SetCurrent method to set the focus to the particular record's column in grid. Here is a code snippet that give the focus to the first column of the add new row in a grid by using AddNewRecord.SetCurrent method. Below is a code snippet

private void gridGroupingControl1_TableControlCurrentCellKeyUp(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlKeyEventArgs e)
{
if( e.Inner.KeyData == Keys.Enter && IsAddNew )
{
//For AddNewRecord..
e.TableControl.Table.AddNewRecord.SetCurrent("parentID");
//For CurrentRecord.
//e.TableControl.Table.CurrentRecord.SetCurrent("parentID");
//For fisrt record.
//e.TableControl.Table.Records[0].SetCurrent("parentID");
}
}

Best regards,
Haneef


PR Prashanth March 15, 2012 02:30 AM UTC

The below code works to avoid new row getting addded on enter key pressed (capture the enter key)

private void gridGroupingControl1_CurrentRecordContextChange_1(object sender, Syncfusion.Grouping.CurrentRecordContextChangeEventArgs e)
{
ShowInformation(e.Action.ToString());
if ((IsEnterPressed) && (e.Action == Syncfusion.Grouping.CurrentRecordAction.LeaveRecordCalled
|| e.Action == Syncfusion.Grouping.CurrentRecordAction.NavigateCalled
|| e.Action == Syncfusion.Grouping.CurrentRecordAction.NavigateComplete
|| e.Action == Syncfusion.Grouping.CurrentRecordAction.LeaveRecordComplete
|| e.Action == Syncfusion.Grouping.CurrentRecordAction.EndEditComplete
|| e.Action == Syncfusion.Grouping.CurrentRecordAction.EndEditCalled
))
{
if (e.Record.Kind == Syncfusion.Grouping.DisplayElementKind.AddNewRecord && IsEnterPressed)
{
//this.gridGroupingControl1.TableDescriptor.AllowNew = false;
e.Cancel = true;
}
}
if (e.Action == Syncfusion.Grouping.CurrentRecordAction.NavigateComplete && IsEnterPressed == false)
{
IsEnterPressed = true;
}
}



PR Prashanth March 15, 2012 02:32 AM UTC

Just missed to mention that i had a requirement of adding only one row at a time from the grid and user shud not be able to see another new row on Enter Key Pressed



AS Asarudheen S Syncfusion Team May 15, 2012 04:50 AM UTC

Hi Tod,

 

Thanks for the update.

 

You can achieve the reported behavior “adding only one row at a time” by using “CurrentRecordContextChange” along with the following code.

 

this.gridGroupingControl1.Table.CurrentRecordContextChange += new Syncfusion.Grouping.CurrentRecordContextChangeEventHandler(Table_CurrentRecordContextChange);

 

       

 

        void Table_CurrentRecordContextChange(object sender, Syncfusion.Grouping.CurrentRecordContextChangeEventArgs e)

        {

            if (e.Action == Syncfusion.Grouping.CurrentRecordAction.EnterRecordComplete && e.Record.GetRecordCount()==1)

            {

                      //type your code here

            }

        }

 

Please let us know if this helps.

 

Regards,

Asarudheen.


Loader.
Live Chat Icon For mobile
Up arrow icon