Solved

list view finditem

Posted on 1998-05-13
9
347 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
 

Expert Comment

by:MarkO
ID: 1447183
I have some code for you as soon as the previous answer is rejected.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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 20 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now