Comment resynchroniser un DataGrid par rapport à sa source de liaison ?
Telle est ma question.

Le contexte est celui-ci : WPF / ADO.NET

J'ai définis dans le fichier MainWindow.xaml deux DataGrid Maître/Détail de la manière suivante.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
...
    <Window.Resources>
        <local:DataSetDBWpf x:Key="dataSetDBWpf"/>
        <CollectionViewSource x:Key="clientsViewSource" Source="{Binding Clients, Source={StaticResource dataSetDBWpf}}"/>
        <CollectionViewSource x:Key="clientCommandesViewSource" Source="{Binding dataRelationClientCommandes, Source={StaticResource clientsViewSource}}"/>
    </Window.Resources
 
...
 
<Grid DataContext="{StaticResource clientsViewSource}" Margin="10" Width="895" VerticalAlignment="Top">
 
...
 
<DataGrid x:Name="clientsDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding}" Grid.Column="0" Grid.Row="0" Margin="0,20,3,0" RowDetailsVisibilityMode="VisibleWhenSelected" Height="171.2" VerticalAlignment="Top" UseLayoutRounding="False" ScrollViewer.CanContentScroll="True" AlternatingRowBackground="LightGray" GotFocus="clientsDataGrid_GotFocus">
 
...
 
<DataGrid x:Name="commandesDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding Source={StaticResource clientCommandesViewSource}}" Grid.Column="0" Grid.Row="1" Margin="0,20,3,0" RowDetailsVisibilityMode="VisibleWhenSelected" Height="200" VerticalAlignment="Top" UseLayoutRounding="False" ScrollViewer.CanContentScroll="True" AlternatingRowBackground="LightGray" GotFocus="commandesDataGrid_GotFocus">
 
...
Dans le code-behind les CollectionViewSource sont initialisées comme suit.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
            DBWpf.DataSetDBWpf dataSetDBWpf = ((DBWpf.DataSetDBWpf)(this.FindResource("dataSetDBWpf")));
            // Load data into the table Clients. You can modify this code as needed.
            DBWpf.DataSetDBWpfTableAdapters.ClientsTableAdapter dataSetDBWpfClientsTableAdapter = new DBWpf.DataSetDBWpfTableAdapters.ClientsTableAdapter();
            dataSetDBWpfClientsTableAdapter.Fill(dataSetDBWpf.Clients);
            System.Windows.Data.CollectionViewSource clientsViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("clientsViewSource")));
            clientsViewSource.View.MoveCurrentToFirst();
            // Load data into the table Commandes. You can modify this code as needed.
            DBWpf.DataSetDBWpfTableAdapters.CommandesTableAdapter dataSetDBWpfCommandesTableAdapter = new DBWpf.DataSetDBWpfTableAdapters.CommandesTableAdapter();
            dataSetDBWpfCommandesTableAdapter.Fill(dataSetDBWpf.Commandes);
            System.Windows.Data.CollectionViewSource clientsCommandesViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("clientsCommandesViewSource")));
            clientsCommandesViewSource.View.MoveCurrentToFirst();
J'aurais besoin dans le déroulement de mon application de resynchroniser le DataGrid Détail nommé ici commandesDataGrid.

Comment puis-je le faire dans le code-behind par programmation ?

Merci d'avance pour vos indications
.