简体   繁体   中英

How can I search in a ListCollectionView?

Until yesterday I used a ListView and bound it to a List<>.
Then I read in some articles that it makes sense to bind the ListView to a ListCollectionView for easy filtering. I did this and it works fine.
But now I don't know how I can find an item in the ListCollectionView.
Until yesterday I used this code, and it works with the List:

List<Artist> selectedArtistsList;
var item = selectedArtistsList.OrderBy(artist => artist.ArtistShowName).FirstOrDefault(artist => artist.ArtistShowName.StartsWith(FindInSelection1.Text, StringComparison.CurrentCultureIgnoreCase));

But it seems for a ListCollectionView there is nothing similar like StartsWith
How can I search in a (filtered) ListCollectionView?

ListCollectionView implements IEnumerable so just cast it to IEnumerable<Artist>

var artist = listCollectionView
                 .Cast<Artist>()
                 .OrderBy(artist => artist.ArtistShowName)
                 .FirstOrDefault(artist => artist.ArtistShowName.StartsWith(FindInSelection1.Text, StringComparison.CurrentCultureIgnoreCase));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM