|
-
Apr 25th, 2001, 03:04 PM
#1
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?
-
Apr 25th, 2001, 03:39 PM
#2
Hyperactive Member
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 !!!!
-
Apr 25th, 2001, 03:56 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|