Showing posts with label wpf collectionview. Show all posts
Showing posts with label wpf collectionview. Show all posts

Saturday, October 31, 2009

WPF And Multiple CollectionViews With Filtering

This one drove me nuts for a bit. You can have multiple views against a single data set. So if you have:

ObservableCollection orders;

you could have one view for Late Orders, another view for New Orders, etc.

You do this using collectionviews. However most of the examples you find show something like this:

ListCollectionView view = (ListCollectionView)CollectionViewSource.GetDefaultView(orders);

However, if you create multiple views like this on orders, you will actually still be working off the default view. If you put a filter on one view, that will actually apply to all views. You need to create the view like this:

ListCollectionView view = new ListCollectionView(orders);

Then you can apply filtering to that view without affecting other views.