Solved

list view finditem

Posted on 1998-05-13
9
360 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

867 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

17 Experts available now in Live!

Get 1:1 Help Now