troubleshooting Question

Searching Listview

Avatar of Jacq
Jacq asked on
Visual Basic Classic
9 Comments1 Solution1161 ViewsLast Modified:
The following function searches a listview and seeks out a string - then sets the focus to the item

What I want to be able to do is find an item by reference to two subitems

For instance the first subitem will be a date and the second will be a time

I can currently find the date in the first subitem - how do I search for the second subitem ?

Jacq


Private Function FindIt(LV As ListView, str As String, Optional iCol As ListFindItemWhereConstants)
   ' FindItem method.
   'Create an integer variable called intSelectedOption
   ' to store the index of the selected button
   ' Create a string variable called strFindMe. Use the InputBox
   ' to store the string to be found in the variable. Use the
   ' FindItem method to find the string. Option1 is used to
   ' switch the FindItem argument that determines where to look.
   
   Dim intSelectedOption As Integer
   Dim strFindMe As String
   

   If Len(str) = 0 Then str = "0"

   strFindMe = str
   intSelectedOption = iCol 'lvwText

   ' FindItem method returns a reference to the found item, so
   ' you must create an object variable and set the found item
   ' to it.
   Dim itmFound As ListItem   ' FoundItem variable.
   
   Set itmFound = LV.FindItem(strFindMe, intSelectedOption, , 0)
   
   ' If no ListItem is found, then inform user and exit. If a
   ' ListItem is found, scroll the control using the EnsureVisible
   ' method, and select the ListItem.
   If itmFound Is Nothing Then  ' If no match, inform user and exit.
      ' MsgBox "No match found"
      ' fall through
      Exit Function
   Else
       itmFound.EnsureVisible ' Scroll ListView to show found ListItem.
       itmFound.Selected = True   ' Select the ListItem.
      ' Return focus to the control to see selection.
'       LV.SetFocus
   End If


End Function
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”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.

-Mike Kapnisakis, Warner Bros