title: binding ComboBox to DataGrid in the code
body: <p>Hi I am trying to dynamically bind ComboBox in the DataGrid inside the code. I saw a few answers related to this but none of them were helpful. The general opinion is to use the DataTempleteColumn but that also gives no result. Here is my code</p>
  
  <pre><code>&lt;Window x:Class="MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="MainWindow" Height="350" Width="525"&gt;
  &lt;Grid&gt;
      &lt;Button Name="ButFill" Content="Fill Grid" HorizontalAlignment="Left" Height="22" Margin="373,65,0,0" VerticalAlignment="Top" Width="62"/&gt;
      &lt;DataGrid x:Name="DaGrid" HorizontalAlignment="Left" Height="134" Margin="25,38,0,0" VerticalAlignment="Top" Width="289" ItemsSource="{Binding}" AutoGenerateColumns="False"&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridTextColumn Header="text" Binding="{Binding Path=col1}"/&gt;
              &lt;DataGridComboBoxColumn Header="combobox" Width="105" ItemsSource="{Binding Path=fill_items}"/&gt;
              &lt;DataGridTemplateColumn Header="template combo" Width="105"&gt;
                  &lt;DataGridTemplateColumn.CellTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;ComboBox Name="TempCombo" ItemsSource="{Binding Path=fill_items}"/&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/DataGridTemplateColumn.CellTemplate&gt;
              &lt;/DataGridTemplateColumn&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>And the code behind is</p>
  
  <pre><code>Imports System.Collections.ObjectModel
  
  Class MainWindow
      Public Property Table As New ObservableCollection(Of Test.dataset)()
      Public Property fill_items As New ObservableCollection(Of String)
      Private Sub ButFill_Click(sender As Object, e As RoutedEventArgs) Handles ButFill.Click
          Dim temp As New Test.dataset()
          Dim cb As New ComboBox
          fill_items.Add("ItemNo1")
          fill_items.Add("ItemNo2")
          cb.ItemsSource = fill_items
          temp.col1 = " Hello"
          temp.col2 = cb
          temp.col3 = cb
          Table.Add(temp)
          DaGrid.DataContext = Table
      End Sub
  End Class
  
  
  Public Class dataset
      Public Property col1 As String
      Public Property col2 As ComboBox
      Public Property col3 As ComboBox
  End Class
  </code></pre>
  
  <p>The problem I see are:</p>
  
  <p>1) The DataGridComboBox Column dosen't show the it until entered in the edit mode.<br>
  2) Both the Combobox are empty, but the Collections "Table" seems to have a combobox.count of 2.</p>
  
  <p>Am I doing anything wrong?
  Could somebody show me a proper complete example of binding ComboBox ?</p>