-
Finding items in a list
Hi,
I'm looking for a code sample (.NET) on vbf. I have previously used it in a project, and since lost it!!
Its the code to Find an item in a listview from the text in a textbox. The code is in the TextChanged event of the textbox and basically finds the item in the listview that it matches - like the "Type name or select from list" textbox works in outlooks address book.
I remember the code was definitely on vbf - and it was more complicated than I'm going to attempt in the time I have to do it....
If anyone could help me find it I'd be very grateful.
Cheers
S.
-
Having spent 3 hours searching this morning... I find the code 30 seconds after posting... isn't that always the case?!!
:)
http://www.vbforums.com/showthread.p...hreadid=200745
(listbox not listview!)
-
Hmm
If i understand you right then this is what you need =)
For I = 0 To List1.ListCount - 1
If List1.List(I) = "My text =)" Then
'Do some stuff
End If
Next I
Hope that helps :)
-
OK so it's not .NET so you will need to adjust the text_change signature and some listbox syntax etc... but my own favorite method for listbox searching - courtesy of ALLAPI !
Code:
'This project needs a ListBox, named List1 and a TextBox, named Text1
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Integer, _
ByVal lParam As Any) As Long
Const LB_FINDSTRING = &H18F
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: [email protected]
'Add some items to the listbox
With List1
.AddItem "Computer"
.AddItem "Screen"
.AddItem "Modem"
.AddItem "Printer"
.AddItem "Scanner"
.AddItem "Sound Blaster"
.AddItem "Keyboard"
.AddItem "CD-Rom"
.AddItem "Mouse"
End With
End Sub
Private Sub Text1_Change()
'Retrieve the item's listindex
List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
End Sub