Welcome to the Xceed Community | Help
Community Search  
More Search Options


I notify, we notify, we all... Wait. No we don't!

Our support department often answers questions from customers who are wondering why grouping, sorting, and statistical functions are not updated when items in the underlying data source are changed, even though they are using a grid bound to an ObservableCollection. After all, an ObservableCollection is supposed to observe its content, isn't it? Well, actually, an ObservableCollection observes its items as a whole. In other words, it only notices when items are added or removed, not when the values of its items change, even if those items implement INotifyPropertyChanged. In comparison, a BindingList DOES listen to INotifyPropertyChanged, and therefore, if its items are modified, the changes will be reflected in the grid. As a result grouping, sorting, and statistical functions will be updated.

This nifty animation illustrates the differences between the two.

Now, if you apply these changes through the grid—in other words, edit an item in the grid—you don't have to worry about it.
Published April 1, 2009 2:57 PM by Jenny [Xceed]



MiddleTommy said:

I thougth the Grid would be listening to the INotifyPropertyChanged for each Item and not from the Collection

April 6, 2009 10:14 AM

Jenny [Xceed] said:

The reason why the grid (or DataGridCollectionView in this case) does not listen to INotifyPropertyChanged on each item is mostly because of performance. What I will do is add a feature request to add a property on the DataGridCollectionView that would "tell" the collection view to listen to each item's property changed.

April 6, 2009 4:10 PM

Ryan said:

I think that the reason that your support department encounters so many support requests for this, is that it appears that the ObservableCollection<T> does not appear to be the culprit, as you claim here (I'm still not convinced).

I also submitted a support ticket for this issue.  Back when I was using an ObservableCollection<T>, I had issues with the statistical functions not updating.  My objects in the ObservableCollection<T> always implemented the INotifyPropertyChanged.  I still believe that the DataRow updates itself from the INotifyPropertyChanged.PropertyChanged event.  Please correct me if this is incorrect.  I made this assumption because the ObservableCollection<T> only notifies of add/removes/ect (changes to the collection, not to the child objects), so it seems logical that the INotifyPropertyChanged.PropertyChanged event is the reason that DataRows are getting update.

I submitted a bug, because it seemed that the DataRow is updating itself when the INotifyPropertyChanged.PropertyChanged event is fired, but the Statistical functions seemed like they were not notified by the DataRows when are updated.

I ended up switching to using a BindingList<T> instead of a ObservableCollection<T>, which did the trick.  The Statistical functions starting working, and I didn't pursue the matter.

However, I still believe that the Xceed WPF DataGrid needs some work in this area.  The DataRows are getting updated via INotifyPropertyChanged, why can't they notify the Statistical Functions that an update is required?

Please don't use "performance" excuse here.  Whenever the user updates a DataRow, the Statistical functions are updated/executed.  Why not when the INotifyPropertyChanged.PropertyChanged event updates the DataRow?

April 9, 2009 11:07 AM

Jenny [Xceed] said:

By performance, we mean memory usage and load-time performance. We were not willing to subscribe to every item's PropertyChanged event since it meant more memory usage and the time to loop on each item and subscribe to it.

In regards to being notified when items are added or removed from the list, we only subscribe to one event, so there is no performance impact there.

The grid updates visually since the cell bindings get notified of the changes, but this only applies to the cells that are realized (i.e., in the viewport) and are therefore in the visual tree.

So yes, we are willing to add a feature to activate/deactivate subscribing to each item's INotifyPropertyChanged notification, but in the current implementation, it is not done.

April 9, 2009 11:38 AM

Tech Side said:

For this blog post from The Tech Side , I will be addressing a few queries that are very common when

July 7, 2011 2:43 PM

Troels said:

Regarding perfomance..

What is the difference in performance between using BindingList (which will loop through the items added and subscribe to the PropertyChangedEvents) and using ObservableCollection and listening to the PropertyChangedEvents in the DataGrid. In my mind, it is just a matter of where it happens.

April 16, 2012 8:21 AM

ObservableCollection (Of T) vs BindingList (Of T) ? | Partager du contenu said:

May 6, 2013 5:21 AM

WPF ObservableCollection<T> vs BindingList<T> | Jptab said:

November 16, 2013 1:30 PM
Anonymous comments are disabled
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.