Kraenys
Kraenys

Reputation: 297

Refresh a Bound DataGrid on a MouseDoubleClick event

On a ListBoxItem, I have a MouseDoubleClick event like this:

<ListBox HorizontalAlignment="Left" Height="84" Margin="97,599,0,0" VerticalAlignment="Top" Width="88">
    <ListBoxItem MouseDoubleClick="Ajout_MouseDoubleClick" Name="Ajouts" Content="Ajouts"/>

The event is as follow:

private void Ajout_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    DbSet<Resultat> res = cnn.Resultat;
    var add = from a in res
              where a.Remarque.Equals("Ajoute")
              select new { a.Groupe_D_alerte, a.LibelléTOTApres, a.LibelléTOTAvant, a.NomChamp, a.NomTable, a.Remarque, a.SiModifie, a.TOTMPMRQ };
    cnn.SaveChanges();
    DonneesBrutes.Items.Refresh();
}

What it is supposed to do is realise a LinQ request into the DbSet called Resultat. It's a simple filter in one column, "Remarque" in this case. Once this filter is applied in the DbSet, I need to refresh the DataGrid binding target of the DbSet "Remarque"

the DataGrid looks like this:

<DataGrid x:Name="DonneesBrutes" IsReadOnly="True" ItemsSource="{Binding Path=.ResultatCollection}" Margin="10,65,0,0" AutoGenerateColumns="False" EnableRowVirtualization="True" RowDetailsVisibilityMode="VisibleWhenSelected">
    <DataGrid.Columns>
        <DataGridTextColumn x:Name="PMRQ" Width="*" Binding="{Binding Path=.TOTMPMRQ}" Header="PMRQ"></DataGridTextColumn>
        <DataGridTextColumn x:Name="LibellePMRQ" Width="*" Binding="{Binding Path=.LibelléTOTApres}" Header="Libellé PMRQ"></DataGridTextColumn>
        <DataGridTextColumn x:Name="Ligne" Width="*" Binding="{Binding Path=.Remarque}" Header="Ligne"></DataGridTextColumn>
        <DataGridTextColumn x:Name="OTM" Width="*" Binding="{Binding Path=.TOTMPMRQ}" Header="OTM"></DataGridTextColumn>
        <DataGridTextColumn x:Name="TOTM" Width="*" Binding="{Binding Path=.SiModifie}" Header="TOTM"></DataGridTextColumn>
        <DataGridTextColumn x:Name="LibelleTOTM" Width="*" Binding="{Binding Path=.LibelléTOTApres}" Header="Libellé OTM"></DataGridTextColumn>
        <DataGridTextColumn x:Name="GA" Width="*" Binding="{Binding Path=.Groupe_D_alerte}" Header="GA"></DataGridTextColumn>
        <DataGridTextColumn x:Name="Discipline" Width="*" Binding="{Binding Path=.NomTable}" Header="Discipline"></DataGridTextColumn>
        <DataGridTextColumn x:Name="DisciplineSubstituee" Width="120" Binding="{Binding Path=.NomChamp}" Header="Discipline Substituée"></DataGridTextColumn>
    </DataGrid.Columns>
</DataGrid>

When I double click, the script execute itself, but it happen nothing, I don't see the filter applied in the DataGrid (To bind datas from DbSet to DataGrid, I use an ObservableCollection)

Upvotes: 0

Views: 49

Answers (1)

Sheridan
Sheridan

Reputation: 69985

WPF is not WinForms. There is no DataGrid.Refresh method. We do not refresh our UI controls. In WPF, we use data binding and implement the INotifyPropertyChanged interface to propagate property changes between the UI and our code behind or view models. Therefore, when we make a change to the data object or objects that are data bound to UI controls, the update is immediate. Therefore, we have no need to 'refresh' anything.

Please see the Data Binding Overview page on MSDN for more information on this subject.

Upvotes: 1

Related Questions