Search code examples
wpflistviewfilter

How do I Filter ListView in WPF?


I have a ListView bound to a collection of items. I do not want to show the items where the property IsDeleted = "1". How can I accomplish this?


Solution

  • I'd use a CollectionView and set the Filter property to an expression:

    var view = CollectionViewSource.GetDefault(GetData());
    view.Filter = i => ((MyType)i).IsDeleted != 1;
    MyListView.DataSource = view;