Reputation: 27
I've been looking for this whole day, but couldn't find it. I need to get index of ListViewItem that contains noncase sensitive string somewhere in it's text.
I know there's FindItemWithText, but it's case sensitive + searches only begining of listviewitem.text
I could iterate through ListView everytime, but I hoped there's a simple solution to this.
Upvotes: 1
Views: 342
Reputation: 460138
It's not true that ListView.FindItemWithText
is case sensitive.
Quote: "The search is case-insensitive."
But you're right. It searches for items that begin with this text.
But you can use LINQ. You can use whatever method you need. If you f.e. want to search for the first item which text contains a specific substring you can use:
ListViewItem firstMatchingItem = listview1.Items.Cast<ListViewItem>()
.FirstOrDefault(i => i.Text.IndexOf("foo", StringComparison.CurrentCultureIgnoreCase) >= 0);
Upvotes: 5