开发者

How can I bind DataGrid row count after a CollectionView filter is applied?

Previously to implementing filtering on the CollectionView, i used this to display the number of rows within the datagrid;

<TextBlock Text="{Binding ElementName=dataGrid1, Path=ItemsSource.Count}" />

I have since implemented a filter as so;

ICollectionView cvs = CollectionViewSource.GetDefaultView(datagrid1.ItemsSource);
cvs.Filter = new Predicate<object>(FilterMethod);
...
public bool FilterMethod(object item) {
    // conditionally returns true/false
}

The TextBlock above still shows the unfiltered count, when visually the filter is removing 开发者_StackOverflow社区items from view. How can I get the TextBlock above to show the row count as a result of the filter?


The problem is that the filter is applied only on the collection view, and not on the item source.

You can do one of 2 thing:

  1. bind to the collection view count (make sure its INPC).
  2. bind to the items control items.count property.

This way the count will be same as what the user see.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜