ListView.FindItemWithText

jdy0803

Well-known member
Joined
Sep 9, 2012
Messages
73
Location
Santa Clarita
Programming Experience
10+
I made ListView of which columns are "Name", "Chart#", "Alt. Chart#", "Birth Date".
I want to searchitem by "Alt. Chart#" using ListView.FindItemWithText method.
How to do this?
 
You don't. FindItemWithText searches for values in either just the first column or in all columns. If you want to search in a specific column other than the first then you'll just have to use a loop or a LINQ query.
 
I'm not going to explain about LINQ in detail because it's too big a subject but, in brief, LINQ in a way to write SQL-like queries against lists of data to simplify application code. In this case, you'd traditionally use a For Each loop but that could be replaced with a LINQ query like so:
VB.NET:
Dim item = myListView.Items.Cast(Of ListViewItem).FirstOrDefault(Function(lvi) lvi.SubItems(2).Text = valueToSearchFor)

If item Is Nothing Then
    MessageBox.Show("No match found.")
Else
    'Use item here.
End If
 
Back
Top