Public Function FindItem(ByVal LV As ListView, ByVal TextToFind As String) As Integer
' Loop through LV’s ListViewItems.
For i As Integer = 0 To LV.Items.Count - 1
If Trim(LV.Items(i).Text) = Trim(TextToFind) Then
' If found, return the row number
Return (i)
End If
For subitem As Integer = 0 To LV.Items(i).SubItems.Count - 1
If Trim(LV.Items(i).SubItems(subitem).Text) = Trim(TextToFind) Then
' If found, return the row number
Return (i)
End If
Next
Next
' If not found, then return -1. Return -1
End Function
Public Sub FindPrinter()
LSPrinters.MultiSelect = False
LSPrinters.FullRowSelect = True
Dim checkInt As Integer = FindItem(LSPrinters, cmbPrint.Text)
If checkInt <> -1 Then
LSPrinters.Items(checkInt).Selected = True
LSPrinters.Focus()
LSPrinters.SelectedItems(0).EnsureVisible()
Else
ToolStripLabel1.Text = "Search string not found"
End If
End Sub
WinApp.png
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.