list view finditem

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.
LVL 1
terencebehAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

terencebehAuthor Commented:
By the way, I need to search all the columns in the listview not just the first column.
0
bin_huwairibCommented:
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
bin_huwairibCommented:
Please reject my answer because it was posted by mestake.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

MarkOCommented:
I have some code for you as soon as the previous answer is rejected.
0
LSILesCommented:
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
MarkOCommented:
Still want to send your some code that will do this for you.
0
MarkOCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
terencebehAuthor Commented:
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
MarkOCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.