I've a problem with the WPF datagrid. I have two ComboBox columns and the second one should set it's datacontext dependant of what is selected in the first one.
ViewModel
public class MyCollection: AbstractViewModel
{
private BindingList<string> _subitems;
public BindingList<string> Subitems
{
get { return _subitems; }
set { _subitems = value; Notify("Subitems");}
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; Notify("Name");}
}
}
Xaml
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding SelectedName}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox SelectedValuePath="Name"
x:Name="CollectionBox"
SelectedValue="{Binding SelectedName}"
DisplayMemberPath="Name"
ItemsSource="{Binding SomeBinding}"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding SelectedSubitem}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox SelectedValue="{Binding SelectedSubitem}"
ItemsSource="{Binding ElementName=CollectionBox, Path=SelectedItem.Subitems}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
The binding for my first ComboBox is ok but I did not see any items in my second ComboBox (the viewmodel has entries for booth of the ComboBoxes); only the TextBox binding works as expected. I tryed it with a ComboBoxColumn as well but with the same result.