Hi guys,Was needing auto filter implemented and I went and created a class to inherit ICollectionView, INotifyPropertyChange and INotifyCollectionChange. My class takes an IList<INotifyPropertyChange> as the source collection so that whenever one of the underlying collection elements has one of its fields changed, the collectionview will test if it matches the filter( the collection view class takes a PropertyDescriptor and a value as a filer; the propertydescriptor is related to the type of the object in my underlying collection)Went on and bound the grid to this collection I realised the grid displays sometimes items that are not matching my criteria. My unit tests point out the collectionview correctly identifies the subset of the source collection matching the filter and it correctly raises the right collection change events. I have a class MyItem : INotifyPropertyChange{ public int FieldA { get { } set { //if value has changed raise the event } }}and an ObservableCollection<MyItem> as the source collection of my collectionview. My observablecollection has just two items in it. On a timer I am changing this FieldA value with onein a range from 0 to 5. I have set the value for my auto filtering to 3-let's say, and here is where it gets interesting and wrong. Whenever first item in the underlying collection gets its FieldA set up to 3it correctly appears on the screen; whenever the second item gets its FieldA set up to 3 - I get an entry on the grid(as I have one item matching my criteria) but the problem isit is displaying the value from the first item. so it looks like my row is actually linked to the first item in my underlyingcollection and I think this is because the row was on the initial load bound to this item.I have changed the RecordContainerGenerationMode from recycling to all the other ones thinking that since is reusing the controls it is still bound to the initial data..it didn't make any difference though.Is this something you can look into and advise? as the problem is a show stopper
Thanks, Stefan
Hi Stefan,
Which version of the control are you using, 7.1 or 7.2?
Hi Joe,
I am using the 7.2 version.
Stefan.
I've looked at your sample and basically there's an issue with using filtering ICollectionView's with both our XamDataGrid as well as ItemsControl and derived classes like ListBox. To see what I mean, add the following code after the XamDataGrid in your sample. It creates a ListBox that binds to the same data source. After applying a filter, the ListBox will display incorrect data as well - it's actually worse because at times it displays more than 2 items.
<ListBox
DisplayMemberPath="Value"
ItemsSource="{Binding ElementName=_grid, Path=DataSource}"
/>
What I've found in my research is that ItemsControl (which is the base class for ListBox) at times will directly access SourceCollection and since the source collection has all items in it, its logic will get out of sync when it handles add/remove notification for filtering purposes. Because when you raise remove, it will still think that the collection has all the items in it because it's using source collection in that case.
XamDataGrid also makes use of underlying source collection. We've entered this as a bug in our bug tracking system and we'll look at if and how we can better support this scenario. In the mean time, you can workaround it by one of two similar ways:
* Make your ICollectionView.SourceCollection implementation return a list that has only the filtered items.
* Don't use ICollectionView. Instead use IBindingList implementation for the data source. The IBindingList implementation would have to represent only the items that are filtered.
Hope this helps,
Sandip
Here is a quick example attached to demonstrate the error. If you apply the filter you would see occasionally the wrong item being displayed even though the collectionview raises the notifycollection changed correctly.
Regards,
Stefan
I'm not sure what is going on here. Can you supply a simplified sample that demonstrates the problem either here or by submitting a support request at http://es.infragistics.com/gethelp?