title: Using SelectedItem property of ComboBox with Linq Anonymous Type
body: <p>In C# 3.5 using a ComboBox to display the results of a LinQ Query. How do I set the SelectedItem property of the ComboBox when the LinQ query is returning an anonymous type?</p>
  
  <p>I set the DataSource of the ComboBox along these lines:</p>
  
  <pre><code>comboBox1.DataSource = from p in db.products
                         select p;
  comboBox1.DisplayMember = "Name";
  comboBox1.ValueMember = "ProductId";
  </code></pre>
  
  <p>If I do that I can choose the selected item by doing something like:</p>
  
  <pre><code>comboBox1.SelectedItem = (from p in db.products 
                            where p.ProductId = 5 
                            select p).First();
  </code></pre>
  
  <p>The problem is that I want to fill a ComboBox with an anonymous type result like:</p>
  
  <pre><code>comboBox1.DataSource = from p in db.products
                         select new
                         {
                             p.ProductId,
                             p.Name
                         };
  </code></pre>
  
  <p>The anonymous type I'm actually using is more complicated then that but it suffices for explanation.</p>