title: How to bind a DataGridComboBoxColumn of a WPF DataGrid
body: <p>My project uses MVVM and I want to bind a <code>DataGridComboBoxColumn</code> to the viewmodel.</p>
  
  <p>The combobox shall have the items "&lt;" (with key "1") and "&lt;=" (with key "2").</p>
  
  <p>First i have an <code>observablecollection</code> with the comboboxitems:</p>
  
  <pre><code>public ObservableCollection&lt;ArithmeticSignData&gt; LowerComparerItems { get; set; }
  </code></pre>
  
  <p>This is the class ArithmeticSignData:</p>
  
  <pre><code>public class ArithmeticSignData
  {
      public ArithmeticSignData(string key, string value)
      {
          ArithmeticSignKey = key;
          ArithmeticSignValue = value;
      }
  
      public string ArithmeticSignKey { get; set; }
      public string ArithmeticSignValue { get; set; }
  }
  </code></pre>
  
  <p>When my viewmodel is initialized i fill the list LowerComparerItems:</p>
  
  <pre><code>private void FillLowerComparerItemsList()
  {
      LowerComparerItems = new ObservableCollection&lt;ArithmeticSignData&gt;();
      LowerComparerItems.Add(new ArithmeticSignData("1", "&lt;"));
      LowerComparerItems.Add(new ArithmeticSignData("2", "&lt;="));
  }
  </code></pre>
  
  <p>The data for the datagrid comes from another observablecollection with an entity framework table as type.
  That table has a column called "low_operator".
  So i thought it would be possible to bind the comboboxcolumn by the following.
  When i open the combobox i can see the items.
  But after starting the app the values from the table are not translated to "&lt;" or "&lt;=".</p>
  
  <pre><code>&lt;DataGridComboBoxColumn x:Name="cbc_LowerComparer"
                                      SelectedItemBinding="{Binding low_operator, NotifyOnSourceUpdated=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                      DisplayMemberPath="ArithmeticSignValue"
                                      Header=" "
                                      Width="30"&gt;
      &lt;DataGridComboBoxColumn.ElementStyle&gt;
          &lt;Style TargetType="ComboBox"&gt;
              &lt;Setter Property="ItemsSource" Value="{Binding Path=DataContext.LowerComparerItems, RelativeSource={RelativeSource AncestorType=DataGrid}}" /&gt;
          &lt;/Style&gt;
      &lt;/DataGridComboBoxColumn.ElementStyle&gt;
      &lt;DataGridComboBoxColumn.EditingElementStyle&gt;
          &lt;Style TargetType="ComboBox"&gt;
              &lt;Setter Property="ItemsSource" Value="{Binding Path=DataContext.LowerComparerItems, RelativeSource={RelativeSource AncestorType=DataGrid}}" /&gt;
              &lt;Setter Property="IsEditable" Value="True"/&gt;
          &lt;/Style&gt;
      &lt;/DataGridComboBoxColumn.EditingElementStyle&gt;
  &lt;/DataGridComboBoxColumn&gt;
  </code></pre>