DataGridCheckboxColumn bind to EF Many-To-Many Relationship

Mar 19, 2009 at 3:56 PM

Hi All. I am working on a project with WPF (DataGrid) and ADO.NET EF.

The relevant piece of the EF model is shown below. Notice the *--* relationship between Location and ArticleClass.

The datagrid in the right hand upper corner (A) lists all the names of the ArticleClasses

The datagrid on the bottom (L) lists all the available Locations.

What I want to do is, when I check the CanHaveAsArticle checkbox of a certain ArticleClass in (A), that a relationship is made (remember the *--*) between the selected Locations in (L) and the checked ArticleClasses in (A).

How can I do this using databinding?

I've tried a ValueConvertor but the instance doesn't know which rows of (L) are selected.

[...]

     <my:DataGrid.Columns>

               <my:DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" IsReadOnly="True"  />

               <my:DataGridCheckBoxColumn Header="CanHaveAsArticle" Binding="{Binding Path=Locations, Converter={StaticResource myRelationshipManager}}" />

           </my:DataGrid.Columns>

[...]

I've thought about binding it to a property in the Window.xaml.vb file where the setter creates the relationship (something like Location.ArticleClass.Add(L.SelectedRow)) and the getter checks whether there is a relationship, but I dont seem to find out how.

Thanks,

Wouter