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.

How to move the SelectedItem to the new inserted record

Thread ID:

Created:

Updated:

Platform:

Replies:

121708 Jan 18,2016 11:26 AM Jan 19,2016 04:02 AM WPF 1
loading
Tags: SfDataGrid
Silvio
Asked On January 18, 2016 11:26 AM

Hi,

I have a SfDatagrid and I insert a new record in my grid using the event "AddNewRowInitiating"
Everything is ok. 
But when the users presses the Return key, the newly created record is appended to the grid (at the last row), but the "SelectedItem" becomes the first record (row) of the datagrid and not the last as I would like.
I would like, in fact, that after the editing is finished, the focus (SelectedItem) is put on the just added record (so the last row).
Is there any way to obtain this?
Is there any event that I can join to in order to set SelectedItem property to the new inserted record ?

Thank you in advance.

Silvio

Ambarish Srinivasan [Syncfusion]
Replied On January 19, 2016 04:02 AM

Hi Silvio,

You can move selection to newly added row by changing the SelectedItem in RowValidated event.

C#

sfdatagrid.RowValidated+=sfdatagrid_RowValidated;


void sfdatagrid_RowValidated(object sender, RowValidatedEventArgs args)

{

    if(sfdatagrid.IsAddNewIndex(args.RowIndex))

    {

        sfdatagrid.Dispatcher.BeginInvoke(new Action(() =>

        {

            sfdatagrid.SelectedItem = args.RowData;

            sfdatagrid.ScrollInView(sfdatagrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex);

        }));

    }
}


Sample:
Sample

Please let us know if you have any questions.

Regards,
Ambarish.

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.

;