title: WPF filter combobox items based on ListView items
body: <p>I'm creating a WPF application using the MVVM design pattern that consists of a ListView and some ComboBoxes.  The ComboBoxes are used to filter the ListView.  What I am trying to accomplish is populating the combobox with items in the related ListView column.  In other words, if my ListView has Column1, Column2, and Column3, I want ComboBox1 to display all UNIQUE items in Column1.  Once an item is selected in the ComboBox1, I want the items in ComboBox2 and ComboBox3 to be filtered based on ComboBox1's selection, meaning that ComboBox2 and ComboBox3 can only contain valid selections.  This would be somewhat similar to a CascadingDropDown control if using the AJAX toolkit in ASP.NET, except the user can select any ComboBox at random, not in order.</p>
  
  <p>My first thought was to bind ComboBoxes to the same ListCollectionView that the ListView is bound to, and set the DisplayMemberPath to the appropriate column.  This works great as far as filtering the ListView and ComboBoxes together goes, but it displays all items in the ComboBox rather than just the unique ones (obviously).  So my next thought was to use a ValueConverter to only return the only the unique items, but I have not been sucessful.</p>
  
  <p>FYI: I read Colin Eberhardt's post on adding a AutoFilter to a ListView on <a href="http://www.codeproject.com/KB/WPF/AutoFilterListView.aspx" rel="nofollow noreferrer">CodeProject</a>, but his method loops through each item in the entire ListView and adds the unique ones to a collection.  Although this method works, it seems that it would be very slow for large lists.</p>
  
  <p>Any suggestions on how to achieve this elegantly?  Thanks!</p>
  
  <p>Code Example:</p>
  
  <pre><code>&lt;ListView ItemsSource="{Binding Products}" SelectedItem="{Binding SelectedProduct}"&gt;
      &lt;ListView.View&gt;
          &lt;GridView&gt;
              &lt;GridViewColumn Header="Item" Width="100" DisplayMemberBinding="{Binding ProductName}"/&gt;
              &lt;GridViewColumn Header="Type" Width="100" DisplayMemberBinding="{Binding ProductType}"/&gt;
              &lt;GridViewColumn Header="Category" Width="100" DisplayMemberBinding="{Binding Category}"/&gt;
          &lt;/GridView&gt;
      &lt;/ListView.View&gt;
  &lt;/ListView&gt;
  
  &lt;StackPanel Grid.Row="1"&gt;
      &lt;ComboBox ItemsSource="{Binding Products}" DisplayMemberPath="ProductName"/&gt;
      &lt;ComboBox ItemsSource="{Binding Products}" DisplayMemberPath="ProductType"/&gt;
      &lt;ComboBox ItemsSource="{Binding Products}" DisplayMemberPath="Category"/&gt;
  &lt;/StackPanel&gt;
  </code></pre>