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

Many to Many (Students , classes example) DataGridComboBoxColumn binding problem

$
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

<StackPanel DataContext="{StaticResource studentViewSource}"
                        Orientation="Horizontal"><DataGrid x:Name="StudentsDataGrid"
                          AutoGenerateColumns="False"
                          EnableRowVirtualization="True"                       
                          ItemsSource="{Binding}"
                          RowDetailsVisibilityMode="VisibleWhenSelected"><DataGrid.Columns><DataGridTextColumn x:Name="idColumn"
                                            Binding="{Binding Id}"
                                            Header="Id"
                                            Width="SizeToHeader" /><DataGridTextColumn x:Name="nameColumn"
                                            Binding="{Binding Name}"
                                            Header="Student Name"
                                            Width="*" /><DataGridTextColumn x:Name="phonesColumn"
                                            Binding="{Binding Phones}"
                                            Header="Phones"
                                            Width="200" /></DataGrid.Columns></DataGrid><DataGrid x:Name="StudentclassesDataGrid"
                          AutoGenerateColumns="False"
                          EnableRowVirtualization="True"
                          Height="200"
                          ItemsSource="{Binding Source={StaticResource studentClassesViewSource}}"
                          RowDetailsVisibilityMode="VisibleWhenSelected"><DataGrid.Columns><DataGridComboBoxColumn Header="Class Name From Combo"
                                                Width="*"
                                                ItemsSource="{Binding Source={StaticResource classViewSource}}"
                                                DisplayMemberPath="Name"
                                                SelectedItemBinding="{Binding Classes}" /></DataGrid.Columns></DataGrid><Button Content="Save"
                        Click="Button_Click" /></StackPanel>


I have 2 problems in the classes datagird :

the DataGridComboBoxColumn don't display the name of the class the student registered in?

When I register a student with new class (creating new row in the DB and selecting a class name ) when I try to save the changes to DB I got error message :Validation failed for one or more entities. See 'EntityValidationErrors' property for more details


Viewing all articles
Browse latest Browse all 18858

Trending Articles



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