Welcome to the Xceed Community | Help
Community Search  

Filter not being applied as Grid cells update

Sort Posts: Previous Next
  •  10-07-2008, 1:47 PM Post no. 15952

    Filter not being applied as Grid cells update

    I have a grid bound to an ObservableList<WorkItemWrapper>. WorkItemWrapper implements INotifyPropertyChanged, and as the various properties in the WorkItemWrappers change/update, they are displayed in real-time on the grid. This works fine.

    I have a Filter applied to the grid that decides whether to display rows based on the WorkItemWrapper.Status property. When the Status changes, it updates in the grid cell, but it doesn't re-apply the filter. I've tried this both with the DataGridCollectionView.Filter and the DataGridCollectionViewSource.Filter--neither fires as the items change. If I manually call the DataGridCollectionView Refresh method, then the filter is works fine.

    So my question is, what is the correct way to apply the Filter to grid cells as they get updated? Thanks in advance.

  •  10-08-2008, 7:10 AM Post no. 15963 in reply to 15952

    Re: Filter not being applied as Grid cells update

    Hi Matt,

    The Filter event inherited from CollectionView effectivelly works a single pass, and then will remain inactive. What you need is to use the DataGrdiCollectionView's Automatic Filtering Capabilities.

    To enable the Automatic Filtering, you can refer to this documentation topic, the rest of this post assumes you are setup accordingly:

    http://doc.xceedsoft.com/products/XceedWpfDataGrid/Filtering_Data.html

    Then, to configure the automatic filtering per your needs, I suggest the following:

    Register to the DataGridControl's Loaded event:
    <xcdg:DataGridControl x:Name="myGrid" Loaded="MyHandler" />

    In the handler, you can prepare the automatic filtering:

    private void MyHandler( object sender, RoutedEventArgs e)

      DataGridContext gridContext = DataGridControl.GetDataGridContext( myGrid );

       //the following line assumes the property to filter by is called "Status".
      gridContext.AutoFilterValues[ "Status" ].Add( myStatus ); //replace myStatus by the status you wish to filter by.
    }



    Marc Laroche
    Software Developer
    Xceed Software Inc.


    I don’t suffer from insanity, I enjoy every minute of it. - Unknown
  •  10-13-2008, 1:54 PM Post no. 16041 in reply to 15963

    Re: Filter not being applied as Grid cells update

    Thanks Marcus. I can get the AutoFilter mode to work, but it still isn't automatically updating the grid rows as the underlying values change. Here are the relevant parts of my code:

    // xaml.cs Constructor
    public ProcessMonitor()
    {
      // Hook up the grid
      DataGridCollectionViewSource src = new DataGridCollectionViewSource();
      dataGrid.ItemsSource = src.View;
      src.AutoFilterMode = AutoFilterMode.Or;
      src.DistinctValuesConstraint = DistinctValuesConstraint.Filtered;
      src.AutoCreateItemProperties = true;
      src.Source = ThreadManager.WorkItems;

        // Hook up the Auto grid filter
        dataGrid.Loaded += new RoutedEventHandler(dataGrid_Loaded);
    }

    void dataGrid_Loaded(object sender, RoutedEventArgs e)
    {
      // Get the grid context
      DataGridContext gridContext = DataGridControl.GetDataGridContext(dataGrid);

      // Set Status autofilter values
      gridContext.AutoFilterValues["Status"].Add(ThreadStatus.Pending);
      gridContext.AutoFilterValues["Status"].Add(ThreadStatus.InProgress);
      gridContext.AutoFilterValues["Status"].Add(ThreadStatus.Aborted);
      //gridContext.AutoFilterValues["Status"].Add(ThreadStatus.Completed);
    }

    As I add processes, I can see their status change in the grid, with the last status being Completed. Since I'm not setting an AutoFilterValue for Completed, I expect the items to disappear from the grid when their status changes to Completed. That's not happening--they just stay there with the Completed value displayed on the grid.

    Update: Let me clarify something that may be relevant. I'm not changing these values *in* the grid, they're being automatically updated and the grid just displays them in read-only mode. All of the updates are displayed correctly on the grid as the changes happen, with the exception of the Filters, which seem to only be applied when the item is initially inserted into the grid.

    Thanks again.

  •  10-15-2008, 11:15 AM Post no. 16124 in reply to 16041

    Re: Filter not being applied as Grid cells update

    Any ideas on this? If there is no way to have the Filters automatically be applied as the data changes, then what is the proper way to Refresh the grid? I suppose I could hook into INotifyPropertyChanged on the ObservableCollection and call the Grid Refresh every time something changes. Or maybe a timer that calls the Refresh every 10 seconds.

    Any other ideas?

  •  10-15-2008, 4:35 PM Post no. 16136 in reply to 16124

    Re: Filter not being applied as Grid cells update

    Hi,

      Since it is a field in your object that changes and not a change in the ObservableCollection, the grid won't refresh.One of the solution would be to raise the NotifyCollectionChanged.Reset event to force the grid to rebind to the DataSource or to implement IBindingList which would raise a ListChanged event.


    Christian Nadeau
    Software Developer
    Xceed Software Inc.
  •  10-16-2008, 11:10 AM Post no. 16160 in reply to 16136

    Re: Filter not being applied as Grid cells update

    Thank you! Changing to BindableList makes everything work... with one exception. If an item is Visible, it is removed from the list when the Status changes. However, if the item is not displaying on the list and the properties change to make it display, it doesn't reappear until I reapply the filters.
  •  10-16-2008, 12:02 PM Post no. 16164 in reply to 16160

    Re: Filter not being applied as Grid cells update

    Hi Matt, 

      The behavior you mention is a bug and I filled a bug report for this. We'll keep you informed on this forum post. 


    Christian Nadeau
    Software Developer
    Xceed Software Inc.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.