Home Forums WPF controls Xceed DataGrid for WPF Getting Filter Row to Talk to Column Filters Example

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • dar100111
    Participant
    Post count: 11
    #45004 |

    I’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 found.";
    Fawzi [Xceed]
    Member
    Post count: 722

    Hi,

    Can you give me more details regarding what are you trying to achieve so that I could have a better understanding.

    dar100111
    Participant
    Post count: 11

    Just wanted to put an example on here. No issue. I’ve seen posts of people trying to display total items vs filtered items. This example works for people that do their bindings in C# not XAML

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