title: Bind datagrid to one ViewModel, column / combobox to another
body: <p>I a have a View Players, the datacontext is set to a ObservableCollection Players from the ViewModel MainPlayerViewModel.</p>
  
  <p>In the View I have a datagrid with columns TeamId, Name and Position.
  I want to bind the TeamId column with a combobox to a list of available teams from the MainTeamViewModel which has a collection property Teams but of course I want the MainPlayerViewModel to be updated whenever I update the team for a player.</p>
  
  <p>I hope you can follow me here..
  This is my xaml:</p>
  
  <pre><code>&lt;data:DataGridTemplateColumn.CellEditingTemplate&gt;
    &lt;DataTemplate&gt;
     &lt;ComboBox DataContext="{Binding MainTeam, Mode=OneWay, Source={StaticResource Locator}}" 
      Height="23" HorizontalAlignment="Left" 
      Name="cmbTeams" VerticalAlignment="Top" Width="100" ItemsSource="{Binding Teams, 
      Mode=TwoWay}" SelectedValue="{Binding Path=Model.teamid, Mode=TwoWay}"   
      DisplayMemberPath="Model.teamid"/&gt;
    &lt;/DataTemplate&gt;
   &lt;/data:DataGridTemplateColumn.CellEditingTemplate&gt;
  </code></pre>
  
  <p>When I edit the cell it shows the list of available teams but the selectedvalue I pick from the list doesn't turn up in the TeamId column</p>
  
  <p>How do I pull this off?</p>
  
  <p>Kind regards,</p>
  
  <p>Mike</p>
  
  <p><strong>UPDATE:</strong>
  Despite the help I received I didn't get it to work binding one View to 2 different Viewmodels.
  Guess the solution offered is long above my head..
  I couldn't set the datacontext of the datagrid to MainTeam because it has an ItemsSource of players and a selecteditem bound twoway to selectedplayer.
  Anyway I decided to keep it 1 View / 1 ViewModel and created a public property on my PlayerViewModel named teamsVM:</p>
  
  <pre><code>    public MainTeamViewModel teamsVM
      {
         get
         {
             return ViewModelLocator.Container.Resolve&lt;MainTeamViewModel&gt;();
         }
      }
  </code></pre>
  
  <p>Now I can set the Itemsource to this new property and my player row get's updated when I change teams:</p>
  
  <pre><code>    &lt;DataTemplate&gt;
       &lt;ComboBox 
         Height="23" HorizontalAlignment="Left" 
         Name="cmbTeams" VerticalAlignment="Top" Width="100" 
         ItemsSource="{Binding teamsVM.Teams, 
         Mode=TwoWay}" SelectedValue="{Binding Model.teamid, Mode=TwoWay}"   
         DisplayMemberPath="Model.teamid" SelectedValuePath="Model.teamid"/&gt;
      &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>Regards,</p>
  
  <p>Mike</p>