Search code examples
c#wpfcollectionviewsource

Is it possible to filter my collectionview by more than one field or column in a table in sql server database


In the code below, i can only filter based on the Surname column in my table, can i filter using more than one table column?

ICollectionView view = CollectionViewSource.GetDefaultView(EmployeeView.ItemsSource);
        view.Filter = m => ((EmployeeMaster)m).Surname.ToLower().Contains(TextBoxSearch.Text.ToLower());

Solution

  • You could try combining the conditions via && or || operators, like this:

    ICollectionView view = CollectionViewSource.GetDefaultView(EmployeeView.ItemsSource); 
    view.Filter = m => ((EmployeeMaster)m).Surname.ToLower().Contains(TextBoxSearch.Text.ToLower()) || ((EmployeeMaster)m).Name.ToLower().Contains(TextBoxSearch.Text.ToLower());