Beansy
Beansy

Reputation: 71

WPF Listview filtered items

I have a listview which is filtered by the text entered by the user.

Is there anyway to get the visible items from the listview?

Upvotes: 3

Views: 695

Answers (2)

Winston Smith
Winston Smith

Reputation: 21882

If you are using virtualization (or introduce it later), any solution which relies on the visible property of the list items may not return all the items which match your filter.

A more reliable solution might be to rerun the predicate against the underlying collection.

Upvotes: 2

Toan Nguyen
Toan Nguyen

Reputation: 11591

In order to achieve what you want, I propose the following solution:

1.

. In your view model you create a list that contains all data obtained from a data source.

var myList = new List<string>();

2.

Create a filtered list which is obtained whenever users enter a text, and you will filter your data based on the entered text.

var filteredList = myList.FindAll(myFilter);

where myFilter is a method to filter data based on some criteria.

3.

Bind your filtered list to the ItemsSource of the list view control.

Hence you can access to the items which are currently shown.

Upvotes: 1

Related Questions