Results 1 to 2 of 2

Thread: Searching listview

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Posts
    4

    Unhappy Searching listview

    I Have been spending much time trying to figure out how to search lisviews with more than one column. After awhile i just went to vbforums and got some code for it but the code doesn't seem to find "My Search Text" anywhere other than the first column can anyone explain this for me please.

    Public Enum elvSearch
    elvSearchText = 1
    elvSearchSub = 2
    elvSearchTag = 4
    End Enum
    Function ListViewFindItem(sFindItem As String, lsvData As ListView, Optional eValueType As elvSearch = elvSearchText + elvSearchSub + elvSearchTag, Optional lSearchFor As Long = lvwPartial, Optional lIndexBeginFrom As Long = 1) As ListItem
    On Error Resume Next

    'Try to find item
    If eValueType And elvSearchText Then
    'Search text
    Set ListViewFindItem = lsvData.FindItem(sFindItem, lvwText, lIndexBeginFrom, lSearchFor)
    End If
    If eValueType And elvSearchSub And (ListViewFindItem Is Nothing) Then
    'Search subitems
    Set ListViewFindItem = lsvData.FindItem(sFindItem, lvwText, lIndexBeginFrom, lSearchFor)
    End If
    If eValueType And elvSearchTag And (ListViewFindItem Is Nothing) Then
    'Search tags
    Set ListViewFindItem = lsvData.FindItem(sFindItem, lvwText, lIndexBeginFrom, lSearchFor)
    End If

    If (ListViewFindItem Is Nothing) = False Then
    'Found a matching item, display it.
    Set lsvData.SelectedItem = ListViewFindItem
    lsvData.SelectedItem.EnsureVisible
    End If
    On Error GoTo 0
    End Function

    'Demonstration routine
    Sub Test()
    Dim oListItem As ListItem

    'Search for "My Search Text"
    Set oListItem = ListViewFindItem("My Search Text", lsvData, elvSearchSub)
    If (oListItem Is Nothing) = False Then
    'Found text in listview, now select item
    Set lsvData.SelectedItem = oListItem
    End If
    End Sub
    What can't be found can't be touched.

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    If you look at this post the second example will need a little modification to include more subitems.

    http://www.vbforums.com/showthread.p...55#post1375255

    If you don't do it this way the only other way is to say
    for each colum
    for each row
    if text in this cell is what i want
    do something
    endif
    next
    next

    just like you would for a 2D array

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width