Home Forums WPF controls Xceed DataGrid for WPF Any way to externally save grid filters

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

    Now that I can (sort of) save my grid sorting/ grouping/ columns, my users want (most importantly) to have saved views that include filters. After some spelunking yesterday and trying to save the grid’s filter values, I am having a hard time.

    Is there any recommended way to get at and save the filter values? I was formerly going to:

            private FilterSettings GetFilterSettings()

            {

                FilterSettings filterSettings = new FilterSettings();

                DataGridCollectionView view = ((DataGridCollectionView)_grid.ItemsSource);

                var filterValues = view.AutoFilterValues;

                foreach (KeyValuePair<string, IList> list in filterValues)

                {

                    FilterSetting filterItem = new FilterSetting { FieldName = list.Key };

                    filterItem.AddRange(list.Value);

                    filterSettings.Add(filterItem);

                }

                return filterSettings;

            } 

     

    This was an effort to get the filter values dictionary. That said, I was getting an exception thrown when trying to iterate the autofiltervalues (not supported exception I think). 

    Imported from legacy forums. Posted by chris (had 1622 views)

    Xceed Support
    Member
    Post count: 5658

    Hi,

      here is the reason / workaround: http://xceed.com/CS/forums/permalink/15939/15939/ShowThread.aspx#15939

    Imported from legacy forums. Posted by Chris [Xceed] (had 1937 views)

    rjune
    Participant
    Post count: 2

    Is this still the case? the link referenced by support doesn’t seem to work

    rjune
    Participant
    Post count: 2

    I’m assuming this is dead, but I didn’t find any other information on how to accomplish this.

    
            void ViewSource_AutoFilterValuesChanged(object sender, AutoFilterValuesChangedEventArgs e)
            {
                if (e.CollectionChangedEventArgs.Action == NotifyCollectionChangedAction.Add)
                {
                    foreach (var item in e.CollectionChangedEventArgs.NewItems)
                        DataGridPreferencesCollection.Add(Name, e.ItemProperty.Name, item);
                }
    
                if (e.CollectionChangedEventArgs.Action == NotifyCollectionChangedAction.Remove)
                {
                    foreach (var item in e.CollectionChangedEventArgs.OldItems)
                        DataGridPreferencesCollection.Remove(Name, e.ItemProperty.Name, item);
                }
    
                Dispatcher.BeginInvoke(new Action(GetRowCounts), DispatcherPriority.DataBind);
            }
    
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.