title: Set default value in WPF ComboBox
body: <p>I am using ComboBox ItemsSource property binding to display items from a List to combo box.</p>
  
  <p>Following is the code:</p>
  
  <pre><code>&lt;ComboBox x:Name="Cmb_Tax" ItemsSource="{Binding TaxList}" 
              DisplayMemberPath="ChargeName" SelectedItem="{Binding 
              SelectedTax,UpdateSourceTrigger=PropertyChanged}" IsEditable="True" 
              IsTextSearchEnabled="True" SelectionChanged="Cmb_Tax_SelectionChanged"/&gt;
  
  Classes.Charges _selected_tax = new Classes.Charges();
  public Classes.Charges SelectedTax
  {
      get
      {
          return _selected_tax;
      }
      set
      {
          _selected_tax = value;
      }
  }
  
  List&lt;Classes.Charges&gt; _taxlist = new List&lt;Classes.Charges&gt;();
  public List&lt;Classes.Charges&gt; TaxList
  {
      get
      {
          return _taxlist;
      }
      set
      {
          _taxlist = value;
          OnPropertyChanged("TaxList");
      }
  }
  </code></pre>
  
  <p>It displays the items in the combo box correctly. </p>
  
  <p>There is a particular item in TaxList <code>"No Tax"</code> which I want to be selected by default in the combo box. This item can be present at any index in the list (Not necessary first or last item of the list).</p>
  
  <p>I am trying to use the following code to set the selected index property of combo box, but sadly its not working.</p>
  
  <pre><code>TaxList = Classes.Charges.GetChargeList("Tax");
  Cmb_Tax.DataContext = this;            
  int i = TaxList.FindIndex(x =&gt; x.ChargeName == tax_name);
  Cmb_Tax.SelectedIndex = i;
  </code></pre>
  
  <p>The Method FindIndex() returns the index of the <code>"No Tax"</code> correctly but when I try assigning it to <code>SelectedIndex</code> of combo the <code>SelectedIndex</code> doesn't change. It stays at -1.</p>
  
  <p><strong>Update1</strong></p>
  
  <pre><code>private void Cmb_Tax_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
      MessageBox.Show(SelectedTax.ChargeName);
  }
  </code></pre>
  
  <p><strong>Update2</strong>
  Updated the code as per suggested by @ElectricRouge</p>
  
  <pre><code>&lt;ComboBox x:Name="Cmb_Tax" ItemsSource="{Binding TaxList, Mode=TwoWay}" 
                        DisplayMemberPath="ChargeName" SelectedItem="{Binding SelectedTax,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
                        IsEditable="True" IsTextSearchEnabled="True" 
                        SelectionChanged="Cmb_Tax_SelectionChanged"/&gt;
  
  
  Classes.Charges _selected_tax = new Classes.Charges();
          public Classes.Charges SelectedTax
          {
              get
              {
                  return _selected_tax;
              }
              set
              {
                  _selected_tax = value;
                  OnPropertyChanged("SelectedTax");
              }
          }
  
          ObservableCollection&lt;Classes.Charges&gt; _taxlist = new ObservableCollection&lt;Classes.Charges&gt;();
          public ObservableCollection&lt;Classes.Charges&gt; TaxList
          {
              get
              {
                  return _taxlist;
              }
              set
              {
                  _taxlist = value;
                  OnPropertyChanged("TaxList");
              }
          }
  
  public void Load_Tax(string tax_name = null, Classes.Charges selected_tax = null)
          {
              TaxList = Classes.Charges.GetParticularChargeList("Tax");
              Cmb_Tax.DataContext = this;
              //Cmb_Tax.SelectedValue = tax_name;
              SelectedTax = selected_tax;
              //int i = TaxList.FindIndex(x =&gt; x.ChargeName == tax_name);
              //Cmb_Tax.SelectedIndex = i;
          }
  </code></pre>
  
  <p>Any idea why this must be happening?
  Also please suggest any other approach to display default in combo box.</p>