Getting Filter Row to Talk to Column Filters Example

Getting Filter Row to Talk to Column Filters Example

’ve seen some questions on this and was trying to figure out the best method for this. I have a couple of labels that show Filtered Results vs Total.

Here’s what I came up with that works well for me. I do all my binding in C# because there are many different queries that load into the same datagrid from a Db2 Server. If there is a better way I’m all ears though!

//FILTER METHODS
        private void Dv_AutoFilterValuesChanged(object sender, AutoFilterValuesChangedEventArgs e)
        {
            Dispatcher.BeginInvoke(new Action(GetRowCounts), DispatcherPriority.Normal);
        }

        private void dvColletionChange(object sender, NotifyCollectionChangedEventArgs e)
        {
            Dispatcher.BeginInvoke(new Action(GetRowCounts), DispatcherPriority.Background);
        }

        private void GetRowCounts()
        {  
            DataGridCollectionView view = this.dataGridControl1.ItemsSource as DataGridCollectionView;
            int allCount = view.SourceItems.Count;
            int filteredCount = view.Count;
           
            if (allCount == filteredCount)
            {
                lblSearchRecords.Content = "";
                btnClearFilter.Visibility = Visibility.Hidden;
            }
            else
            {
                lblSearchRecords.Content = filteredCount.ToString() + " filtered results";
                btnClearFilter.Visibility = Visibility.Visible;
            }
        }

Binding DataGridCollection View in C#

               DataGridCollectionView dv =  new DataGridCollectionView(dt.DefaultView);
                dv.DistinctValuesConstraint = DistinctValuesConstraint.Filtered;
                dv.AutoFilterMode = AutoFilterMode.And;
//ADD TO DETECT COLLECTION CHANGED
                ((INotifyCollectionChanged)dv).CollectionChanged += new 
                NotifyCollectionChangedEventHandler(this.dvColletionChange);
                dataGridControl1.ItemsSource = dv;                
                dv.AutoFilterValuesChanged += Dv_AutoFilterValuesChanged;
                dataGridControl1.SelectionChanged += dataGridControl1_SelectionChanged;
                lblBgw1.Content = dv.SourceItems.Count.ToString() + " shipments foun