title: How to implement editable DataGridComboBoxColumn in WPF DataGrid
body: <p>I want to enable the user to edit some data in WPF DataGrid ( from the .net Framework 4.0). The "instruments" column should allow the user to select an available intrument from a static list or to write a free text.
  My DataGrid is binded to data using MVVM. I've tried many solutions I've found in internet but none of them work correctly.
  Here is my code:</p>
  
  <pre><code>&lt;DataGrid Margin="0,6" ItemsSource="{Binding Path=Orders}" AutoGenerateColumns="False"  CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="True"&gt;
  &lt;DataGrid.Columns&gt;
  &lt;DataGridComboBoxColumn Header="Instrument" MinWidth="140"                                      
   ItemsSource="{x:Static ViewModel.Instruments}" SelectedItemBinding="{Binding Path=SelectedInstrument}"&gt;
   &lt;DataGridComboBoxColumn.EditingElementStyle&gt;
     &lt;Style TargetType="ComboBox"&gt;
       &lt;Setter Property="IsEditable" Value="True"/&gt;
     &lt;/Style&gt;                  
   &lt;/DataGridComboBoxColumn.EditingElementStyle&gt;                
  &lt;/DataGridComboBoxColumn&gt;   
  &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>The drop-down-list is shown correctly. The field can be edited with any text, but it sets a null to the SelectedInstrument after the drop-down is closed for the free text. It works only for the selected item. I've tried to change to SelectedValueBinding, but it doesn't help.</p>
  
  <p>How to implement this requirements properly? Can someone post here a working sample?</p>
  
  <p><strong>Additional</strong>:
  Orders is ObservableCollection
  Order has Property like string Title, DateTime Ordered, string SelectedInstrument,
  Instruments is a string[]</p>
  
  <p><strong>Solutions</strong>:
  Following suggest as a workaround from <a href="https://stackoverflow.com/users/761357/bathineni">bathineni</a> works:</p>
  
  <pre><code>&lt;DataGrid Margin="0,6" ItemsSource="{Binding Path=Orders}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="True"&gt;
   &lt;DataGrid.Columns&gt;
    &lt;DataGridTemplateColumn Header="Instrument" MinWidth="140"&gt;
     &lt;DataGridTemplateColumn.CellTemplate&gt;
      &lt;DataTemplate&gt;
       &lt;TextBlock Text="{Binding Path=SelectedInstrument, Mode=OneWay}"/&gt;
      &lt;/DataTemplate&gt;
     &lt;/DataGridTemplateColumn.CellTemplate&gt;
     &lt;DataGridTemplateColumn.CellEditingTemplate&gt;
      &lt;DataTemplate&gt;
       &lt;ComboBox IsEditable="True" Text="{Binding Path=SelectedInstrument}" 
        ItemsSource="{x:Static ViewModel.Instruments}"/&gt;                   
      &lt;/DataTemplate&gt;
     &lt;/DataGridTemplateColumn.CellEditingTemplate&gt;
    &lt;/DataGridTemplateColumn&gt;   
   &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>