Live update of Master-Details view?

I am using C#.

Question 1. I have successfully created a Master-Details view that works as intended; when I expand the parent row, it shows the correct child grid with objects from its ObservableCollection property.

But how do I get the child grid to update in real time when a new object is added to the underlying collection?

My Master grid updates itself just fine whenever I change a property programmatically. I want the same thing to occur in the Details view. What am I missing about the data binding here?

Note that my Details class implements the INotifyPropertyChanged and INotifyPropertyChanging interfaces and events, just like the class used for my Master grid data. Additionally, in my parent grid, LiveDataUpdateMode is set to "AllowLiveUpdate, AllowChildViewUpdate".


Question 2. I autogenerate the columns in my grids. In my Master, I have successfully created additional columns programmatically. I want to do the same thing in my Details grid, but I cannot get additional columns to appear using the following code:

orderGrid.AutoGeneratingRelations += OrderGrid_AutoGeneratingRelations; // I wire the event to the handler below


private void OrderGrid_AutoGeneratingRelations(object sender, AutoGeneratingRelationsEventArgs e)

{ 

e.GridViewDefinition.DataGrid.AllowSorting = true;  // setting child grid properties works as expected


e.GridViewDefinition.DataGrid.Columns.Add(new GridTextColumn() { MappingName = "Customer", HeaderText = "Customer" }); // creating a column in the child grid does not work for me

}

What am I missing?


Thank you SF!


1 Reply

VS Vijayarasan Sivanandham Syncfusion Team September 6, 2021 05:59 PM UTC

Hi Ken,

Thank you for contacting Syncfusion Support.

Please find answer for your queries below 
Queries 
Solutions 
 
But how do I get the child grid to update in real time when a new object is added to the underlying collection? 
 
 
Based on provided information we suspect that your ChildDataGrid bounded underline model does not contains default constructor. So, new object not added into your ChildDataGrid.

 
Your requirement can be achieved by using underlying data object must be defined with default constructor. Otherwise, create instance of data object by handling AddNewRowInitiating event.

If the data source implements INotifyCollectionChanged interface, then SfDataGrid control will automatically refresh the UI when item is added, removed or while list cleared.
When an item is added/removed in ObservableCollection, SfDataGrid automatically refresh the UI as ObservableCollection implements INotifyCollectionChanged

For more information related to LiveDataUpdateMode and AddNewRow, please refer the user guide documentation,
 
 
Based on provided information we have prepared the sample for achieve your requirement.

 
 

Please have a look at this sample and let us know if you have any concerns in this. 
 
 
I want to do the same thing in my Details grid, but I cannot get additional columns to appear using the following code: 

Regards,
Vijayarasan S 


Loader.
Up arrow icon