Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

list view finditem

Posted on 1998-05-13
9
Medium Priority
?
605 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

715 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