Example #1
0
        private void OnAutoFilterSelectClearAllClick(object sender, RoutedEventArgs e)
        {
            var fe = sender as FrameworkElement;

            if (fe == null)
            {
                return;
            }

            var dg = fe.FindParent <DataGridControl>();

            if (dg == null)
            {
                return;
            }

            var viewSource = dg.ItemsSource as DataGridCollectionView;

            if (viewSource == null)
            {
                return;
            }

            int               filters           = 0;
            Button            button            = (Button)sender;
            AutoFilterControl autoFilterControl = button.TemplatedParent as AutoFilterControl;
            string            columnFieldName   = autoFilterControl.AutoFilterColumn.FieldName;
            bool              selectAll         = ((string)button.Tag) == "1";

            using (viewSource.DeferRefresh())
            {
                ObservableHashList autoFilterValues = viewSource.AutoFilterValues[columnFieldName] as ObservableHashList;
                using (autoFilterValues.DeferINotifyCollectionChanged())
                {
                    autoFilterValues.Clear();
                    if (selectAll)
                    {
                        IList distinctValues = viewSource.DistinctValues[columnFieldName];
                        foreach (object value in distinctValues)
                        {
                            autoFilterValues.Add(value);
                        }
                        filters += distinctValues.Count;
                    }
                }

                if (selectAll)
                {
                    ListBox listBox = autoFilterControl.DistinctValuesHost as ListBox;
                    listBox.SelectAll();
                }
            }
        }
        internal override void RefreshDistinctValuesForField(DataGridItemPropertyBase dataGridItemProperty)
        {
            if (dataGridItemProperty == null)
            {
                return;
            }

            if (dataGridItemProperty.CalculateDistinctValues == false)
            {
                return;
            }

            // List containing current column distinct values
            HashSet <object> currentColumnDistinctValues = new HashSet <object>();

            ReadOnlyObservableHashList readOnlyColumnDistinctValues = null;

            // If the key is not set in DistinctValues yet, do not calculate distinct values for this field
            if (!(( DistinctValuesDictionary )this.DistinctValues).InternalTryGetValue(dataGridItemProperty.Name, out readOnlyColumnDistinctValues))
            {
                return;
            }

            ObservableHashList columnDistinctValues = readOnlyColumnDistinctValues.InnerObservableHashList;

            // We use the DistinctValuesSortComparer if present, else the SortComparer for the DataGridItemProperty, else,
            // the Comparer used is the one of the base class.
            IComparer distinctValuesSortComparer = dataGridItemProperty.DistinctValuesSortComparer;

            if (distinctValuesSortComparer == null)
            {
                distinctValuesSortComparer = dataGridItemProperty.SortComparer;
            }

            using (columnDistinctValues.DeferINotifyCollectionChanged())
            {
                DataGridVirtualizingQueryableCollectionViewGroupRoot rootGroup = this.RootGroup as DataGridVirtualizingQueryableCollectionViewGroupRoot;

                Debug.Assert(rootGroup != null);

                object[] distinctValues = rootGroup.GetItemPropertyDistinctValues(dataGridItemProperty);

                foreach (object distinctValue in distinctValues)
                {
                    // Compute current value to be able to remove unused values
                    currentColumnDistinctValues.Add(distinctValue);
                }

                DataGridCollectionViewBase.RemoveUnusedDistinctValues(
                    distinctValuesSortComparer, currentColumnDistinctValues, columnDistinctValues, null);
            }
        }