PDA

View Full Version : How can I search with Listview and Array ??



khoa140383
01-05-2012, 12:55 AM
I have a listview, I want to search Item with condition *& textbox1 &* ( contain ). Please see attached file and help.

Dim a(), r&, c&, rs&, cs&, i, ii
i = Timer
With ListView1
' Do some common settings
.View = lvwReport
.Gridlines = True
.HideColumnHeaders = False

' Create the column headers
.ColumnHeaders.Add , , "COLUMN 1", 100
.ColumnHeaders.Add , , "COLUMN 2", 100
.ColumnHeaders.Add , , "COLUMN 3", 100

' Populate test range with 3 columns of data
With Range("A1:C65500")
'.Formula = "=COLUMN()& ""-""&ROW()"
a() = .Value ' <-- copy test data into array
End With

' Copy test data from a() to ListView1
rs = UBound(a, 1)
cs = UBound(a, 2)

For r = 1 To rs
With .ListItems.Add(, , a(r, 1))

For c = 2 To cs
.SubItems(c - 1) = a(r, c)
Next
End With
Next

End With
ii = Timer
MsgBox (ii - i)

Have a nice day !!!

mancubus
01-06-2012, 08:53 AM
wellcome to vbax.

check this out:
http://msdn.microsoft.com/en-us/library/aa443432(v=vs.60).aspx