Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

list view finditem

Posted on 1998-05-13
9
Medium Priority
?
654 Views
Last Modified: 2008-02-01
I am trying to program a find function that will locate the matching record (partial or whole word) in the list view.
Eg. Looking for "auto", I have tried the following:

Set itmFound = ListView.FindItem("auto", lvwText, , lvwPartial)
Set itmFound = ListView.FindItem("auto", lvwSubItem, , lvwPartial)

The above will work for matching of full word only. Please advise how to achieve the find function. Thanks.
0
Comment
Question by:terencebeh
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 1

Author Comment

by:terencebeh
ID: 1447180
By the way, I need to search all the columns in the listview not just the first column.
0
 
LVL 5

Expert Comment

by:bin_huwairib
ID: 1447181
terencebeh,

Try the following:

Set itmFound = ListView.FindItem("auto", lvwText, lvwPartial)
Set itmFound = ListView.FindItem("auto", lvwSubItem, lvwPartial)

I just removed the coma before lvwPartial.


Best regards
Bin Huwairib
0
 
LVL 5

Expert Comment

by:bin_huwairib
ID: 1447182
Please reject my answer because it was posted by mestake.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:MarkO
ID: 1447183
I have some code for you as soon as the previous answer is rejected.
0
 

Expert Comment

by:LSILes
ID: 1447184
I haven't really thought out how to used it, BUT you could use the InStr fuction.  The syntax is as follows:

InStr([start, ]string1, string2[, compare])

Just check out your VB Help.  It's all in there.  Good function!  I love it.   =)  Hope it helps.

---LSILes
les@livingscriptures.com
0
 

Expert Comment

by:MarkO
ID: 1447185
Still want to send your some code that will do this for you.
0
 

Accepted Solution

by:
MarkO earned 60 total points
ID: 1447186
I have found the FindItem method to be "???".  Here is a function I wrote and use in some of my programs which will manually find the text in the ListItems and subitems.  I added the Partial search for your needs.

Just add this function to your program and call it passing the Text, Listview control etc.

'--------------Sample Call to function
Dim item As ComctlLib.ListItem
Set item = Search("Auto", ListView1, 0, True, False)


'--------------Code for function
Public Function Search(Text As String, ListView As ComctlLib.ListView, _
                       Optional StartIndex As Integer, _
                       Optional SearchSubItems As Boolean = False, _
                       Optional MatchWholeWord As Boolean = False) As ComctlLib.ListItem
                       
Dim tmpItem As ComctlLib.ListItem
Dim FoundItem As Boolean
Dim x As Integer

   ' default startindex if missing
   If IsMissing(StartIndex) Then
      StartIndex = 0
   End If
   
   For Each tmpItem In ListView.ListItems
      If tmpItem.Index >= StartIndex Then
         If tmpItem.Text = Text _
         Or (Not MatchWholeWord And Left$(tmpItem.Text, Len(Text)) = Text) Then
            FoundItem = True
            Exit For
         Else
            If SearchSubItems Then
               For x = 1 To ListView.ColumnHeaders.Count - 1
                  If tmpItem.SubItems(x) = Text _
                  Or (Not MatchWholeWord And Left$(tmpItem.SubItems(x), Len(Text)) = Text) Then
                     FoundItem = True
                     Exit For
                  End If
               Next x
            End If
         End If
      End If
      If FoundItem Then Exit For
   Next tmpItem
   
   If FoundItem Then
      Set Search = tmpItem
   End If
   
End Function
0
 
LVL 1

Author Comment

by:terencebeh
ID: 1447187
Hi MarkO,
How do I found out whether there is a matching found ? I tried
If item = Nothing then
...


but VB does not accept this statement.
0
 

Expert Comment

by:MarkO
ID: 1447188
The Correct use of Nothing is:

  If Item is Nothing then ... (not =)

or if not logic is prefered:

  If not Item is Nothing then ...



The above statement would work fine.

MarkO

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question