DataGrid: Binding Child Table to ComboBox

Dec 10, 2008 at 6:38 PM
Edited Dec 10, 2008 at 6:46 PM
I'm using Entity Framework and have successfully bound a typed list of object to datagrid (ObjectQuery<department />). Alle classes derive from EntityObject.
<dg:DataGrid x:Name="dg" ItemsSource="{Binding}" Margin="10" AutoGenerateColumns="False" Background="#80909090" AlternationCount="2">
  <dg:DataGridTextColumn Binding="{Binding DepartmentID, Mode=OneWay}" Header="ID" Width="SizeToCells"></dg:DataGridTextColumn>
  <dg:DataGridTextColumn Binding="{Binding Name}" Header="Department Name" Width="SizeToCells"></dg:DataGridTextColumn> 
  <dg:DataGridTextColumn Binding="{Binding Budget, StringFormat=C}" Header="Budget" Width="SizeToCells"></dg:DataGridTextColumn>
  <dg:DataGridTextColumn Binding="{Binding StartDate, StringFormat=d}" Header="StartDate" Width="SizeToCells"></dg:DataGridTextColumn>
  <dg:DataGridTextColumn Binding="{Binding Administrator, Mode=OneWay}" Header="Administrator" Width="SizeToCells"></dg:DataGridTextColumn>
  <dg:DataGridComboBoxColumn Header="Course List" Width="200" 
     TextBinding="{Binding Path=Course.Title}" ItemsSource="{Binding Path=Course}" >
The DataGrid binds well and shows all columns. However, the DataGridComboBoxColumn shows nothing. No exception or warning under all circumstances. The Course property is defined as this: public global::System.Data.Objects.DataClasses.EntityCollection<course /> Course Each course object has a property Title. I'm struggling with the definition formatted bold in the source:
   TextBinding="{Binding Path=Course.Title}" ItemsSource="{Binding Path=Course}" 
Some other variations I tried didn't work either.  Could somebody bring some light into this? The object is filled correctly and has valid data in it, checking DataContext of Window with debugger. When I use same dataource for a drop down and assign in SelectionChanged event the DataContext using code to the element's property department.Course it's working well and the data appear in the combobox. This is code which works well:
// Same data bound to ListBox works well
private void departmentList_SelectionChanged(object sender, SelectionChangedEventArgs e) 
  Department department = (Department)this.departmentList.SelectedItem;
  courseList.DataContext = department.Course;

Thanks a lot,
Dec 18, 2008 at 8:12 PM
Try setting the ItemsSource binding in the ElementStyle and EditingElementStyle.  For more on this see this post,