M.Nasiri
M.Nasiri

Reputation: 45

Multiple Filter Listview C#

So i have two Textboxes where the user can Filter either the BoxNumber or Barcode in a ListView. Now i want to use multiple filtering, however one of them is not working without any error. If i comment one of them out the other one is working why?

        CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(parkingListe.ItemsSource);
        view.Filter = UserFilter;
        view.Filter = UserFilter_box;




        //Text Search (Barcode Search) 
        private bool UserFilter(object item)
        {
            if (String.IsNullOrEmpty(txtFilter.Text))
                return true;
            else
                return ((item as ParkingClass).parking_barcode.IndexOf(txtFilter.Text, StringComparison.OrdinalIgnoreCase) >= 0);
  
        }

        //Box Search (Box Inhalt Search)
        private bool UserFilter_box(object item)
        {
            if (String.IsNullOrEmpty(boxFilter.Text))
                return true;
            else
                return ((item as ParkingClass).parking_box.IndexOf(boxFilter.Text, StringComparison.OrdinalIgnoreCase) >= 0);
        }
   

Upvotes: 0

Views: 138

Answers (1)

Stephen Gilboy
Stephen Gilboy

Reputation: 5825

CollectionView.Filter can only be set with one filter Predicate so when you assign it twice you're just changing the previous filter value.

You should combine both methods into a single filter function for the CollectionView

Upvotes: 2

Related Questions