---
title: "WPF Linq a collection to include or exclude items"  
description: "WPF Linq a collection to include or exclude items"  
author: "Anonymous User"  
published: 2013-12-09  
updated: 2013-12-10  
canonical: https://www.mindstick.com/forum/1756/wpf-linq-a-collection-to-include-or-exclude-items  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# WPF Linq a collection to include or exclude items

I have 3 comboboxes that the [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) can [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) a value. On the SelectionChanged [event](https://www.mindstick.com/articles/167719/marquee-hire-benefits-of-event-lighting-hire-london) of each [combobox](https://www.mindstick.com/articles/57/display-record-according-to-combobox-selection-in-csharp-dot-net) will [filter](https://www.mindstick.com/forum/1176/filter-in-a-xml-file-in-c-sharp) out an [observablecollection](https://www.mindstick.com/forum/1367/difference-between-observablecollection-and-bindinglist-in-wpf) that would only [populate](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box) another [collection](https://www.mindstick.com/articles/1718/collections-in-java) based on the values. The comboboxes contains a blank at the top for the user to select not to [apply](https://www.mindstick.com/articles/13148/discover-to-apply-make-up-like-a-professional-supermodel) the filter on that column.

Is there a [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) way to use linq to do this?

## Replies

### Reply by Anonymous User

Hi Jayprakash,\

You xaml might be like this:

```
<ComboBox x:Name="cmb1"
SelectionChanged="Selector_OnSelectionChanged"><ComboBox x:Name="cmb2" SelectionChanged="Selector_OnSelectionChanged"><ComboBox x:Name="cmb3"
SelectionChanged="Selector_OnSelectionChanged"> And code of the handler:var someCollection = new List<int>(); // some your
collection// stubsExpression<Func<int, bool>> predicate1 = (x)
=> true;Expression<Func<int, bool>> predicate2 = (x)
=> true;Expression<Func<int, bool>> predicate3 = (x)
=> true; // real predicatesif (cmb1.SelectedIndex >= 0)    predicate1 = (x)
=> x == (int)cmb1.SelectedValue;if (cmb2.SelectedIndex >= 0)    predicate2 = (x)
=> x == (int)cmb2.SelectedValue;if (cmb3.SelectedIndex >= 0)    predicate3 = (x)
=> x == (int)cmb3.SelectedValue; // eval and outlstBox.Items = someCollection.Where(predicate1)                            
.Where(predicate2)                             .Where(predicate3)                            
.ToList();
```


---

Original Source: https://www.mindstick.com/forum/1756/wpf-linq-a-collection-to-include-or-exclude-items

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
