Results 1 to 3 of 3

Thread: Listview Search

  1. #1
    ATommasi
    Guest

    Red face Listview Search

    Does anyone know how to search a specific column in a listview for text, and put all the rows that where the text mathced into another listview?

  2. #2
    Hyperactive Member techman2553's Avatar
    Join Date
    Mar 2001
    Location
    <- To your left.
    Posts
    362
    This will loop through all of the items in a given column of the Sorce ListView Control (ListView1) to search for a match with the SearchString using the Like Operator. Any matches found will be copied to the Destination ListView Control (ListView2).

    Use Column Number 0-x to specify a column, where 0 is the first (Text Property) of the ListItems.

    Look up "Like" in the VB help files for a description of how to structure a String for SearchString.

    Code:
    Private Sub Command1_Click()
      Call SearchColumn(0, "*.TXT")
    End Sub
    
    Private Sub SearchColumn(ColumnNumber As Integer, SearchString As String)
      Dim Counter As Integer
      ListView2.ListItems.Clear
      For Counter = 0 To ListView1.ListItems.Count - 1
        If ColumnNumber = 0 Then
          If (ListView1.ListItems(Counter).Text Like SearchString) = True Then
            Call ListView2.ListItems.Add(, , ListView1.ListItems(Counter).Text)
          End If
        Else
          If (ListView1.ListItems(Counter).SubItems(ColumnNumber) Like SearchString) = True Then
            Call ListView2.ListItems.Add(, , ListView1.ListItems(Counter).SubItems(ColumnNumber))
          End If
        End If
      Next Counter
    End Sub
    I hope that helps !!!!
    ----------

  3. #3
    ATommasi
    Guest
    Thanks, that code works perfectly. I have to modify it a bit because i want all the subitems of the first listview to be added to the seconed, but that's not a big deal. At least now I know how to do it.
    Thanks again.

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