title: Retrieving SelectedItem from ComboBox error
body: <p>I am trying to retrieve the selected value of a combo box but I am having a weird problem occurring. </p>
  
  <p>I have tried:</p>
  
  <p><code>myCombo.SelectedItem.ToString()</code> and I am getting back the value:</p>
  
  <pre><code>System.Windows.Controls.ComboBoxItem: myValue.
  </code></pre>
  
  <p>I have then tried:</p>
  
  <pre><code>ComboBoxItem item = ((ComboBoxItem)myCombo.selectedItem);
  item.content.toString();
  </code></pre>
  
  <p>This works fine if selected index is 0 or 1. However if any of the other indexes are selected it displays the exception:</p>
  
  <blockquote>
    <p>InvalidCastException was unhandled Unable to case object of type
    'System.String' to type 'System.Windows.Controls.ComboBoxItem'</p>
  </blockquote>
  
  <p>The only difference between index 0 and 1 and the others are, index 0 and 1 are added manually via the XAML whereas the others are added programatically from a database query like below:</p>
  
  <pre><code>string myValue = reader["my_table_column"].toString();
  myCombo.Items.Add(myValue);
  </code></pre>
  
  <p>Thanks for any help you can provide</p>
  
  <p><strong>UPDATE</strong>
  As Wayne Tanner requested below is a snippet of the XAML for the combo box</p>
  
  <pre><code>&lt;ComboBox Height="23" HorizontalAlignment="Left" Margin="26,6,0,0" Name="cboIVRGroup" SelectedIndex="0" VerticalAlignment="Top" Width="143" SelectionChanged="cboIVRGroup_SelectionChanged"&gt;
                      &lt;ComboBoxItem Content="All IVRs" /&gt;
                      &lt;ComboBoxItem Content="Unassigned IVRs" /&gt;
                  &lt;/ComboBox&gt;r the combo box
  </code></pre>