Home Forums WPF controls Xceed DataGrid for WPF Asynchronous Grid Filter

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

    Hi

    I’m looking for the correct way to continuously filter the grid while a user is typing the filter criteria in a text box.

    Currently I handle the TextChanged event on the text box and then initiate a new delegate. In this delegate I call

    ((DataGridCollectionView)this.grid.ItemsSource).Refresh();

    The problem I have is that the grid still does the refresh on the UI thread, since the UI still freezes directly after typing each character.

    What is the correct way to this?

    Cheers

    Imported from legacy forums. Posted by Barry (had 3190 views)

    User (Old forums)
    Member
    Post count: 23064

    Probably you shouldn’t call .Refresh() since it will rebind the grid. Can’t you just set DataGridCollectionView.Filter to filter what you need?

    http://doc.xceedsoft.com/products/XceedWpfDataGrid/Xceed.Wpf.DataGrid~Xceed.Wpf.DataGrid.DataGridCollectionView~Filter.html

    Imported from legacy forums. Posted by nat (had 438 views)

    User (Old forums)
    Member
    Post count: 23064

    I’ve tried to do that, but the UI still freezes for a few seconds after typing every character.

    Here’s the code…

    private delegate void FilterTreadDelegate();

    void txtVoucherNumber_TextChanged(object sender,
    System.Windows.Controls.TextChangedEventArgs e)
    {
    Dispatcher.BeginInvoke(
    DispatcherPriority.ApplicationIdle,
    new FilterTreadDelegate(FilterWorker));
    }

    private void FilterWorker()
    {
    DataGridCollectionView temp = (DataGridCollectionView)this.grid.ItemsSource;
    temp.Filter = new Predicate<object>(FilterVoucher);
    }

    private bool FilterVoucher(object item)
    {
    vwVouchers ve = item as vwVouchers;
    bool bReturnV = false;

    if (txtVoucherNumber.Text.Trim() != “”)
    {
    if (ve.VoucherNumber.Trim().ToLower().StartsWith(txtVoucherNumber.Text.Trim().ToLower()))
    {
    bReturnV = true;
    }
    }
    else
    {
    bReturnV = true;
    }
    return bReturnV;
    }

    Imported from legacy forums. Posted by Barry (had 546 views)

    Xceed Support
    Member
    Post count: 5658

    Reapplying a filter after each keystroke is not ideal since it will cause lags like the ones you are seeing. I suggest that you refilter the grid (by calling Refresh) when the Enter key or a button is pressed.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 4056 views)

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