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

Is there a property to obtain the current NewRow Entity ?

Hi,

I'm binding a SfDatagrid to a detail form using the SelectedItem property, for example in this way:

  SelectedItem="{Binding Path=Selection, Mode=TwoWay}"  

where "Selection" is a suitable member on my ViewModel class.
This works very good.

However when the user is inserting a new record on the grid (using the AddNewRowInitiating event), the SelectedItem property is null.
So I don't have any binding on the detail form to the new created record until the record is really inserted in the datagrid.
But I would like to have a property (or a method) in the datagrid to obtain also the currenctly adding record.
Is there any possibility to obatain this record?

I've also thougth this workaroud. I have this method when I insert a new record:

        private void SfDataGrid_AddNewRowInitiating(object sender, Syncfusion.UI.Xaml.Grid.AddNewRowInitiatingEventArgs args)
        {
          args.NewObject = new CustomerDTO();
        }

I could save this newly created record (CustomerDTO) in a private field of the form. And then define a my own property to return it.
But what event must I join in order to set this field to null when the record is added to the datagrid and it not yet bindend to the "add new Row"?

So what can you suggest me to solve this problem ?

Silvio


1 Reply

SP Sowndaiyan Paulpandi Syncfusion Team January 19, 2016 12:53 PM UTC

Hi Silvio,

Thanks for contacting Syncfusion Support.

We have analyzed your query. You can achieve your requirement “Set the private field CustomerDTO as null” by using the RowValidated event like the below code example,

Code Example [ C# ]


sfdatagrid.RowValidated += sfdatagrid_RowValidated;

void sfdatagrid_RowValidated(object sender, RowValidatedEventArgs args)

{

    if(sfdatagrid.IsAddNewIndex(args.RowIndex))

    {
      
// here you can set your private field as null
        CustomerDTO = null;

     }
}




Regards,

Sowndaiyan


Loader.
Live Chat Icon For mobile
Up arrow icon