views:

665

answers:

0

I've got a gridview where the collums binds its data to the Datagrid.DataContext in Page_Loaded:

private void Shema_Loaded(object sender, RoutedEventArgs e)
    {
        GridName.DataContext = AllPdiLines;
    }

I want a grid where one of the cels in every line contains acombobox with selectable values which then binds to the datagrid datasource when selected. Should be easy, but a cant bind the itemscollection for the combobox.

The xaml looks like this:

<data:DataGrid x:Name="GridName" 
ItemsSource="{Binding}"     
AutoGenerateColumns="False"
SelectionMode="Single"
ScrollViewer.VerticalScrollBarVisibility="Auto" 
ScrollViewer.HorizontalScrollBarVisibility="Auto" 
Margin="4">
<data:DataGrid.Columns>
 <data:DataGridTemplateColumn Header="First name">
  <data:DataGridTemplateColumn.CellEditingTemplate>
   <DataTemplate>
    <TextBox Text="{Binding FirstName,Mode=TwoWay}"/>
   </DataTemplate>
  </data:DataGridTemplateColumn.CellEditingTemplate>
 </data:DataGridTemplateColumn>
 <data:DataGridTemplateColumn Header="LastName" CanUserSort="True">
  <data:DataGridTemplateColumn.CellTemplate>
   <DataTemplate>
    <TextBox Text="{Binding LastName,Mode=TwoWay}"/>
   </DataTemplate>
  </data:DataGridTemplateColumn.CellTemplate>
 </data:DataGridTemplateColumn>
 <data:DataGridTemplateColumn Header="Country">
  <data:DataGridTemplateColumn.CellEditingTemplate>
   <DataTemplate>
    <ComboBox x:Name="cbxQ" IsEnabled="True"
     SelectedItem="{Binding Country,Mode=TwoWay}" 
     ItemsSource="{Binding Countries, Source={StaticResource CountryDataSource}}" 
     ItemTemplate="{StaticResource CountryListTemplate}"/>
   </DataTemplate>
  </data:DataGridTemplateColumn.CellEditingTemplate>
 </data:DataGridTemplateColumn>                    
</data:DataGrid.Columns>

So, I set the DataContext for the DataGrid and the two first collumns binds nicely, but how can I set the datasource for selectable values in the ComboBox in every row.

regards Øyvind