Home Forums WPF controls Xceed DataGrid for WPF Xceed Grid -> Reapply filters after data refresh

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #41541 |

    Hi,

    I’m new to Xceed, and I can’t find any answer for my problem. I’m using  Xceed Datagrid to display data (original hmm?). Per user requirements, the grid is reloaded at every screen change (users can go back and forth to compare data between screens for instance) to make sure they have the latest data available.

    Everything is fine, except that filters are not reapplied after the grid has been refreshed.

    Groups and sorting directions are nicely kept however.

     

    Here is the code I use.

    To save the filters (it works fine, altough there’s probably a nicer way to do it..), we keep them in memory :

      var filters = ((DataGridCollectionView)CommandeCifGrid.ItemsSource).AutoFilterValues;

                foreach(string key in filters.Keys)

                {

                    IList values;

                    if (filters.TryGetValue(key, out values) && values.Count > 0)

                    {

                        Filters.Add(key,(ObservableHashList)values);

                    }  

                }

     

    When the datagrid have been refreshed, I reapply the values like this :

         foreach(string key in Filters.Keys)

                {

                    ObservableHashList values;

                    if (Filters.TryGetValue(key, out values) && values.Count > 0)

                    {

                        ((DataGridCollectionView)CommandeCifGrid.ItemsSource).AutoFilterValues[key].Add(values);   

                    }

      } 

     

    When it is done, the dataGrid display the little icon that say “Hey I’m filtered”, but none of the filters are selected, and none are applied. The data are not filtered.

     

    How do I achieve this? 

    Imported from legacy forums. Posted by François (had 77 views)

    User (Old forums)
    Member
    Post count: 23064

    Finally I got it.. my mistake.

    When the filters are applied, it needs to be passed value by value, and not by throwing the whole collection in one shot :

    foreach (string key in Filters.Keys)

                        {

                            ObservableHashList values;

                            if (Filters.TryGetValue(key, out values) && values.Count > 0)

                            {

                                ((DataGridCollectionView)dgc.ItemsSource).AutoFilterValues[key].Clear();

                                foreach (var val in values)

                                {

                                    ((DataGridCollectionView)dgc.ItemsSource).AutoFilterValues[key].Add(val);

                                }

                            }

                        }

     

    Hope that help someone… 

    Imported from legacy forums. Posted by François (had 48 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.