title: Populating DataGridComboBox in Grid with SelectedItem
body: <p>I am trying to get a <code>DataGridComboBoxColumn</code> (Or <code>DataGridTemplateColumn</code> with a <code>ComboBox</code>) to populate a list of ports and default each row to the port that is already stored in the database. I have got a <code>DataGridTemplateColumn</code> with a <code>ComboBox</code> populating the Ports, but I cannot seem to get it to select what is already stored in the database.</p>
  
  <p>I'm using Entity Framework and I have 2 tables, 'Route' and 'Port'. 'Route' has 2 foreign keys for a 'Destination Port' and a 'Arrival Port'. </p>
  
  <p>I have 2 ObervableCollections, one for the list of ports, and another for the list of routes. In the routes collection there is a 'Port1' and 'Port2' for Destination/Arrival respectively. </p>
  
  <p>This is what I currently have:</p>
  
  <pre><code>&lt;DataGridTemplateColumn.CellTemplate&gt;
      &lt;DataTemplate&gt;
          &lt;ComboBox ItemsSource="{Binding DataContext.PortCollection, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" 
                                            DisplayMemberPath="PortName"
                                            SelectedItem="{Binding DataContext.RouteCollection, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
                                            SelectedValue="{Binding DataContext.Port1, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}"
                                            SelectedValuePath="PortId"&gt;
          &lt;/ComboBox&gt;
      &lt;/DataTemplate&gt;
  &lt;/DataGridTemplateColumn.CellTemplate&gt;
  </code></pre>
  
  <p>But as I said it is only listing the available ports, and is otherwise blank. Sorry if I haven't made myself too clear, I'm not very good at articulating, generally. </p>
  
  <p>Here are my collections:</p>
  
  <pre><code>public ObservableCollection&lt;Port&gt; PortCollection { get; set; }
  
  //List of Routes
  private ObservableCollection&lt;Route&gt; _RouteCollection;
  
  public ObservableCollection&lt;Route&gt; RouteCollection
  {
      get { return _RouteCollection; }
      set
      {
          _RouteCollection = value;
          Set(() =&gt; RouteCollection, ref _RouteCollection, value);
      }
  }
  </code></pre>
  
  <p>There's clearly something obvious wrong as this must be quite a common thing to do, but I've been going mad for 4 hours on this just getting this far! :(</p>
  
  <p>Many thanks</p>