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.
Unfortunately, activation email could not send to your email. Please try again.

Got to new bottom left of new row on enter

Thread ID:

Created:

Updated:

Platform:

Replies:

61583 May 29,2007 01:49 PM May 15,2012 12:50 AM Windows Forms 10
loading
Tags: GridControl
Tod Golding
Asked On May 29, 2007 01:49 PM

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.


haneefm [Syncfusion]
Replied On May 29, 2007 03:12 PM

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

Tod Golding
Replied On May 29, 2007 04:07 PM

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

haneefm [Syncfusion]
Replied On May 29, 2007 07:42 PM

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

Tod Golding
Replied On May 31, 2007 01:19 PM

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

haneefm [Syncfusion]
Replied On May 31, 2007 05:34 PM

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

Tod Golding
Replied On May 31, 2007 06:03 PM

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

haneefm [Syncfusion]
Replied On June 1, 2007 04:37 PM

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

Prashanth
Replied On March 14, 2012 10:30 PM

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;
}
}


Prashanth
Replied On March 14, 2012 10:32 PM

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


Asarudheen S [Syncfusion]
Replied On May 15, 2012 12:50 AM

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.


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.

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.

;