title: Set selected value of a combo box
body: <p>I've done a bit of searching on this, but nothing seems to have quite exactly the answer I'm looking for. Basically I have a combo box and an object in the combo box. I'd like to set the value of the combo box to the value of the object.</p>
  
  <pre><code>ComboBox cbPayee;
  // populate with a bunch of "Payee" objects
  Payee myObj; // this is my payee object which I get from my database
  
  cbPayee.SelectedValue = myObj // this is what I'd like to do, but it doesn't work
  </code></pre>
  
  <p>I'm thinking that maybe this has something to do with the fact that the Payee object in the combo box is a different memory location than myObj, but I'm not sure how to overcome this.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is how the ComboBox is populated</p>
  
  <pre><code>foreach(Payee payee in PayeeManager.GetPayees())
  {
      cbPayee.Items.Add(payee);
  }
  </code></pre>
  
  <p><strong>EDIT #2</strong></p>
  
  <p>I'm fairly new to WPF so maybe my binding is not set up properly?</p>
  
  <pre><code>&lt;Window x:Class="Budget.TransactionWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="New Transaction" Height="450" Width="450" Loaded="Window_Loaded"&gt;
      &lt;Window.Resources&gt;
          &lt;DataTemplate x:Key="PayeeOutput" DataType="Budget.LINQ.Payee"&gt;
              &lt;StackPanel Margin="0 0 0 0" Orientation="Horizontal"&gt;
                  &lt;TextBlock FontWeight="bold" Text="{Binding Path=Name}" /&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid&gt;
          &lt;ComboBox Height="25" HorizontalAlignment="Left" Margin="73,50,0,0" Name="cbPayee" VerticalAlignment="Top" Width="300" ItemTemplate="{StaticResource PayeeOutput}" /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>