title: How can I bind data to a ComboBox inside from DataGrid?
body: <p>This is the user control which I'm working on. The items in the first comboBox are gonna be the same in dataGridColumn GroupID.</p>
  
  <p><img src="https://i.stack.imgur.com/dQdsx.png" alt="enter image description here"></p>
  
  <p>The code to show in the first comboBox is</p>
  
  <pre><code>    &lt;ComboBox ItemsSource="{Binding}" Name="GroupComboBox" SelectedValuePath="GroupID" DisplayMemberPath="GroupName" Grid.Column="1" Margin="5" /&gt;
  
      private void LoadGroups()
      {
          NorthwindDataContext dc = new NorthwindDataContext();
  
          var groups = (from p in dc.Group
                        select p);
  
          this.DataContext = groups;
      }
  
      private void LoadStudents()
      {
          NorthwindDataContext dc = new NorthwindDataContext();
  
          var students = (from p in dc.Student
                           select p);
  
          dataGrid1.ItemsSource = students;
      }
  </code></pre>
  
  <p>But in the another comboBox, don't appear any item in it.</p>
  
  <pre><code>            &lt;DataGridTemplateColumn Header="GroupID"&gt;
                  &lt;DataGridTemplateColumn.CellTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;ComboBox ItemsSource="{Binding}" SelectedValuePath="GroupID" DisplayMemberPath="GroupName" /&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/DataGridTemplateColumn.CellTemplate&gt;
              &lt;/DataGridTemplateColumn&gt;
  </code></pre>
  
  <p>How can I bind it?</p>
  
  <p>I was thinking in put all the Groups in a list, but I'm not sure it'll be a good way because I'd need to convert my query in a list.</p>
  
  <p><strong>UPDATE 1:</strong></p>
  
  <p>I had to remove this line:</p>
  
  <pre><code>            &lt;DataGridComboBoxColumn Header="GroupID" ItemsSource="{Binding DataContext, RelativeSource={RelativeSource AncestorType=UserControl}}" SelectedValuePath="GroupID" DisplayMemberPath="GroupName" /&gt;
  </code></pre>
  
  <p>for</p>
  
  <pre><code>            &lt;DataGridTemplateColumn Header="GroupID"&gt;
                  &lt;DataGridTemplateColumn.CellTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;ComboBox ItemsSource="{Binding DataContext, RelativeSource={RelativeSource AncestorType=UserControl}}" SelectedValuePath="GroupID" DisplayMemberPath="GroupName" SelectedValue="{Binding GroupID}" /&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/DataGridTemplateColumn.CellTemplate&gt;
              &lt;/DataGridTemplateColumn&gt;
  </code></pre>