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

SfDataGrid how to update ItemsSource after deleting SelectedItems

Hi all,

I have a collection of custom objects that I bind to a SfDataGrid with a Multiple SelectionMode.
In a delete button event I delete those selected objects in the collection and rebind it to the grid.
However the grid doesn't update accordingly. I tried setting ItemsSource to null before but this causes a crash.

=== code to fill the grid

_List = datamodel.GetProducts();
_Grid = new SfDataGrid(this);
_Grid.ItemsSource = list;

==== and in delete event

var selected = _Grid.SelectedItems.Cast<Product>().ToList();
foreach (var product in selected)
     _List.Remove(product);
_Grid.ItemsSource = _List;

=====

Is there an update method on the grid? Or am I missing something?

Kind regards,
Michel.

P.S.: I put this thread in General because there is no SfDataGrid option in the Control dropdown.

2 Replies

MU Michel Uiterwijk May 22, 2015 07:20 PM UTC

Hi all,

After some real digging into the issue I found that everything works when the list is an ObservableCollection.
There is the magic as the grid automatically responds to changes in the list.

Hope this helps others as well... ;-)

Cheers, Michel.


SC Saranya CJ Syncfusion Team May 25, 2015 06:42 AM UTC

Hi Michel,

Thank you for your update. Please let us know if you require any other assistance on this.

Regards,
Saranya

Loader.
Live Chat Icon For mobile
Up arrow icon