1

I am using a ListView which is bound to a ICollectionView (ListCollectionView -> ObservableCollection) While loading a file containing data the collection gets filled. Every data item has a boolean flag, which indicates if it must be shown in the listview or must be hidden.

Currently I have done this in an ugly way. I am filling first the collection (listview) with data. The user can see this. After filling it I start a routine which filters (ICollectionView.Filter) the items, which do not match. The listview item count shrink at that moment.

Is there a better way to implement this?

Ferhat
  • 471
  • 3
  • 9
  • 21

1 Answers1

3

Just set the Filter before you start filling the collection:

ObservableCollection<Foo> collection = new ObservableCollection<Foo>();
ICollectionView view = CollectionViewSource.GetDefaultView();
view.Filter = YourFilterMethod;
// Fill the collection
collection.Add(...);
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
  • Thanks for the answer. But is it not possible to use a kind of condition? The Listview shows only items which have a matching condition (a boolean property is true/false) – Ferhat Feb 12 '11 at 23:56