Hello,
I'm doing an exercise, and I'd like to ask for your advice. I added an ADO.NET Entity Data Model starting from the Northwind database, selecting the Customers and Orders tables. I also added the datasource, and I was able to create (via drag'n'drop):
- a combobox with the company names of the Customers
- a gridview with the Orders related to the customer that is selected in the combobox
Here is a part of the xaml automatically generated:
Code:
    <Window.Resources>
        <CollectionViewSource x:Key="CustomerViewSource" d:DesignSource="{d:DesignInstance {x:Type local:Customer}, CreateList=True}"/>
        <CollectionViewSource x:Key="CustomerOrdersViewSource" Source="{Binding Orders, Source={StaticResource CustomerViewSource}}"/>
    </Window.Resources>
<Grid DataContext="{StaticResource CustomerViewSource}">
 <ComboBox HorizontalAlignment="Left"  Width="150" Margin=" 10" DisplayMemberPath="CompanyName" ItemsSource="{Binding}" />
        <DataGrid x:Name="OrdersDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding Source={StaticResource CustomerOrdersViewSource}}" Grid.Row="1" RowDetailsVisibilityMode="VisibleWhenSelected">
            <DataGrid.Columns>
                <DataGridTextColumn x:Name="CustomerIDColumn" Binding="{Binding CustomerID}" Header="Customer ID" Width="SizeToHeader"/>
                <DataGridTextColumn x:Name="EmployeeIDColumn" Binding="{Binding EmployeeID}" Header="Employee ID" Width="SizeToHeader"/>
                <DataGridTextColumn x:Name="FreightColumn" Binding="{Binding Freight}" Header="Freight" Width="SizeToHeader"/>
[...]
In the Window_Loaded event I assigned the CollectionViewSources and loaded data as follows:

Code:
    Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs) Handles MyBase.Loaded

        CustomerViewSource = CType(Me.FindResource("CustomerViewSource"), System.Windows.Data.CollectionViewSource)
        CustomerOrdersViewSource = CType(Me.FindResource("CustomerOrdersViewSource"), System.Windows.Data.CollectionViewSource)
        northwind = New NorthwindEntities

        northwind.Customers.Load()

        CustomerViewSource.Source = northwind.Customers.Local

    End Sub
Running the code, if I select a different customer using combobox, the datagrid is automatically updated (I didn't have to add code to combobox selectionchanged, I think because of FK_Orders_Customers). But if I try to edit datagrid cell, I receive the following error: 'EditItem' is not allowed for this view.

So I added this line to the Window_Loaded method:
Code:
CustomerOrdersViewSource.Source = northwind.Orders.Local
Now datagrid's edit is ok but the combobox behavior does not refresh datagrid content anymore. Is there a way I can solve this issue without adding code to the combobox selectionchanged? Thank you very much!