Results 1 to 21 of 21

Thread: [RESOLVED] ListView search always returns not found

Threaded View

  1. #1

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Resolved [RESOLVED] ListView search always returns not found

    What am I doing wrong? Everything I attempt on the listview for searching returns no object. Did I set something up wrong? I have tried partial and whole searches and nothing turns up. txtSearch containd "ACT" (without the quotes)
    Code:
    Private Sub cmdSearch_Click()
    Dim oListItem As ListItem
    
        Set oListItem = ListViewFindItem(txtSearch, ListView1, elvSearchText, lvwWhole)
        
        If (oListItem Is Nothing) = False Then
            'Found text in listview, now select item
    '        Set ListView1.SelectedItem = oListItem.Selected
        End If
        
    End Sub
    Code:
    Option Explicit
    
    'The function below searches a listview for a specific item. The code will search the text, subitems and tags of the listview items.
    
    Public Enum elvSearch
        elvSearchText = 1
        elvSearchSub = 2
        elvSearchTag = 4
    End Enum
    
    'Purpose     :  Finds and selects and item in a listview
    'Inputs      :
    '               lvFind                  The listview to search for the item in.
    '               [eValueType]            The type of values to search:
    '                                       1 = Searches the text items.
    '                                       2 = Searches sub items.
    '                                       4 = Searches the item tags.
    '               [lSearchFor]            The type of matching required:
    '                                       lvwWhole = Find whole word.
    '                                       lvwPartial = Find a partial match.
    '               [lIndexBeginFrom]       The item index to begin the search from, for recursive
    '                                       searches. See the index property of the listitem.
    '                                       property of the listitem.
    'Outputs     :  N/A
    'Author      :  Andrew Baker
    'Date        :  25/11/2000 03:17
    'Notes       :
    'Revisions   :
    
    Function ListViewFindItem(sFindItem As String, lvFind 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 = lvFind.FindItem(sFindItem, lvwText, lIndexBeginFrom, lSearchFor)
        End If
        If eValueType And elvSearchSub And (ListViewFindItem Is Nothing) Then
            'Search subitems
            Set ListViewFindItem = lvFind.FindItem(sFindItem, lvwText, lIndexBeginFrom, lSearchFor)
        End If
        If eValueType And elvSearchTag And (ListViewFindItem Is Nothing) Then
            'Search tags
            Set ListViewFindItem = lvFind.FindItem(sFindItem, lvwText, lIndexBeginFrom, lSearchFor)
        End If
        
        If (ListViewFindItem Is Nothing) = False Then
            'Found a matching item, display it.
            Set lvFind.SelectedItem = ListViewFindItem
            lvFind.SelectedItem.EnsureVisible
        End If
        On Error GoTo 0
    End Function
    Attached Images Attached Images  

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