Preserve Filtering after ItemsSource Changes

Posted by: richardinva on 19 September 2017, 11:06 am EST

    • Post Options:
    • Link

    Posted 19 September 2017, 11:06 am EST

    I’ve got a c1datagrid that I’m populating using the ItemsSource property, and I use the UI to set the filters for the grid. After the detail edit of one of the records in the grid, I re-load the data by setting the Itemssource again. Once the data are re-loaded, none of the filters I set earlier are effective (the filter settings are still shown in the UI, but they do not filter the content of the data grid at all). The exception to this is multivalued filters, which seem be preserved across itemsource changes. All other filters cease to be effective.

    Is there a way to preserve the c1datagrid filtering after you’ve switched the itemssource of the c1datagrid?

  • Posted 19 September 2017, 11:06 am EST

    Hello,

    In order to preserve the filter in C1DataGrid, you need to save the FilterState of the filtered columns. And after changing the ItemsSource of C1DataGrid, use FilterBy() method to apply the previous filter conditions. here is the suggested code:

    [csharp]

    DataGridFilterState fs;

        void c1DataGrid_FilterChanged(object sender, DataGridFilterChangedEventArgs e)
        {
            if (c1DataGrid.Columns[1].FilterState!=null)
                fs = c1DataGrid.Columns[1].FilterState;
        }
    
        private void btn_Change_Click(object sender, RoutedEventArgs e)
        {
            c1DataGrid.ItemsSource = d2;
            c1DataGrid.FilterBy(c1DataGrid.Columns[1], fs);
        }
    

    [/csharp]

    Please find the attached sample implementing your requirements and let me know if I missed something.

    Regards,

    Prashant

    2015/09/WPF_C1DataGrid_Filter.zip

  • Posted 8 June 2018, 1:53 am EST

    I have the same situation. I re-apply the the filters (multi-columns) and it does not work.

    I saw this post (hopefully yours work) and even your app (the main ComponentOne source) still does not work.

  • Posted 8 June 2018, 1:55 am EST

    The 1st image is after I run your app and set the filter.

    The 2nd image is when I click the Change Item Source button, but filter does not apply correctly.

  • Posted 8 June 2018, 1:58 am EST

    here is mine the same issue.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels