SfDataGrid refresh when Collection property changed

Hi,

I want to refresh SfDataGrid when ItemSource (Observable collection) property is changed (changed value).

For standard DataGrid I use the code below and it works. But it doesnt work for SfDataGrid.

WPF
ItemsSource="{Binding CollectionName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"


C#
public ObservableCollection<SomeClass> CollectionName
{get=> _collectionName; set_collectionName =value;OnPropertyChanged();}}

CollectionViewSource.GetDefaultView(CollectionName).Refresh();


How to make it work for SfDataGrid?

Regards

Jakub



5 Replies 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team July 21, 2022 04:39 PM UTC

Hi Jakub Olichwier,

We are a little unclear about your scenario. The collection is reinitialized or updated the values updated properly in SfDataGrid. 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 you add, or remove an item in ObservableCollection, SfDataGrid automatically refreshes the UI as ObservableCollection implements INotifyCollectionChanged. But when you do the same in List, SfDataGrid will not refresh the UI automatically. Please find the sample in the attachment.

UG Link: https://help.syncfusion.com/wpf/datagrid/data-binding

https://help.syncfusion.com/wpf/datagrid/columns#autogeneratecolumns-with-different-modes

If we misunderstood your requirement, please provide more information regarding the requirement. This would help us to proceed further.

Regards,

Vijayarasan S


Attachment: Sample_68b1e74.zip


JO Jakub Olichwier July 22, 2022 09:30 AM UTC

Hi Vijayarasan,

Thank you for your reply.

In fact it requiers to clarify it better.


I update properties of object inside observable colelction. It doesn't refresh the UI so I use

A command bind to button to run


CollectionViewSource.GetDefaultView(CollectionName).Refresh();

For standard DataGrid it works (refreshes the UI). For SfDataGrid the command above doesn't refresh the UI.

Regards

Jakub




VS Vijayarasan Sivanandham Syncfusion Team July 25, 2022 03:21 PM UTC

Hi Jakub Olichwier,

We suspect that your reported scenario is changed property value in the collection does not reflect in SfDataGrid. We have prepared the sample based on a provided code snippet from our end. Please find the tested sample in the attachment.

If you still facing the same issue, please provide more information related to your query?

  • Code snippet related to updating properties of the object inside the observable collection
  • If possible, kindly modify the sample based on your scenario.

Kindly revert to us with the above requested details. It will be more helpful for us to check the possibilities to resolve the reported problem.

Regards,

Vijayarasan S


Attachment: Sample_And_Video_Demo_b7000890.zip

Marked as answer

JO Jakub Olichwier August 5, 2022 12:32 PM UTC

Hi  Vijayarasan,

Thank you for the answer. Reinitializing helped.

Regards

Jakub



VS Vijayarasan Sivanandham Syncfusion Team August 5, 2022 12:43 PM UTC

Hi Jakub Olichwier,

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.

Regards,

Vijayarasan S


Loader.
Up arrow icon