Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Many to Many (Students , classes example) Datagrid xaml binding

$
0
0

I have a WPF / entity framework application, my model have student , class entities there is a many to many association/relation between student and class (student can have many classes and class have many students )

student [ Id ,Name , Classes(Navigation property) ] classes [ Id ,Title, Students(Navigation property ]

in this case the entity framework don't show the join/relation table.

i have a 2 DataGirds as master details, student grid is the master and classes is details

how can i set the binding to classes gird (the details gird) so i can add and remove classes to the selected student?

what i want is to select a student from the master grid and add or remove his classes

this is my classes gird

<DataGrid x:Name="classesDataGrid"
                      AutoGenerateColumns="False"
                      EnableRowVirtualization="True"
                      Height="200"
                      ItemsSource="{Binding Source={StaticResource studentClassesViewSource}}"
                      RowDetailsVisibilityMode="VisibleWhenSelected"
                      Width="380"><DataGrid.Columns><DataGridComboBoxColumn Header="Class Name From Combo"
                                            Width="*"

                                            ItemsSource="{Binding Source={StaticResource classViewSource}}" 
                                            DisplayMemberPath="Name"

                                            SelectedItemBinding="{Binding Students}" 

                                            /><!--<DataGridTextColumn x:Name="durationColumn"
                                        Binding="{Binding Duration}"
                                        Header="Duration"
                                        Width="SizeToHeader" />--></DataGrid.Columns>

This scenario works fine when the relation is one to many but i couldn't make it work for many to many relations .

I've found a similar post on this problem on msdn, but the conclusion that this scenario can't be done (in datagrid at least).



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>