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
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
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
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?
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
Hi Vijayarasan,
Thank you for the answer. Reinitializing helped.
Regards
Jakub
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