|
-
Oct 20th, 2001, 09:37 AM
#1
Thread Starter
Hyperactive Member
Searching a listbox
I am writing a program that should have the ability to search through the contents of a list box. I would like to set it up so that as you type text into a textbox it compares that text to the text in the listbox. If the text in the list box does not partain to the text in the textbox it want it removed. And when the text box it cleared I want the listbox to be restored to the original contents.
I know this is kind of confusing but if anyone can help me I would appreciate it.
Thanks,
Mark
-
Oct 20th, 2001, 09:40 AM
#2
PowerPoster
Is this what you're after?
VB Code:
Dim i As Long
For i = List1.ListCount - 1 To 0 Step -1
If UCase(Text1.Text) <> UCase(List1.List(i)) Then
'remove it
List1.RemoveItem i
End If
Next i
-
Oct 20th, 2001, 09:45 AM
#3
Member
you mean kinda like in a help index? as you put in each additional letter the index jumps to the next closest match in the list? what I can suggest is when a key is pressed in the text box, go through each item in listbox and see if the text in the textbox exists in each line of the list box (maybe use InStr?) and if it's not on the line then ListBox.Remove ListBox.ListIndex or something like that. I'm sure there is a better way to do it but that's my 2 cents.
-
Oct 20th, 2001, 09:50 AM
#4
Thread Starter
Hyperactive Member
I want it so that if I type the Letter "E" it will eliminate everything that does not begin with the letter "e" or "E". I know how to do the eliminating part but I don't know how to do the comparing part.
-
Oct 20th, 2001, 09:53 AM
#5
PowerPoster
Small modification to code I already gave. Would be an idea to explain yourself properly
VB Code:
Dim i As Long
For i = List1.ListCount - 1 To 0 Step -1
If UCase(Left$(Text1.Text, 1)) <> UCase(Left$(List1.List(i), 1)) Then
'remove it
List1.RemoveItem i
End If
Next i
-
Oct 20th, 2001, 09:57 AM
#6
Thread Starter
Hyperactive Member
that one gave me an compile error that says "Type-declaration character does not match declared data type"
-
Oct 20th, 2001, 10:01 AM
#7
Fanatic Member
How are you initially populating the listbox?
If from a database table, then do a SQL Select query based on your entered text in the textbox, this will allow the list box only to be populated with data for each added (or deleted) keystroke.
Code:
"SELECT myDispValue FROM myTable WHERE myDispValue LIKE '" & myText & "%'"
You must clear the listbox before each re population of the resulting recordset.
-
Oct 20th, 2001, 10:01 AM
#8
PowerPoster
-
Oct 20th, 2001, 10:11 AM
#9
PowerPoster
Works fine...
Example using above code...
-
Oct 20th, 2001, 10:16 AM
#10
Thread Starter
Hyperactive Member
It works great now.....I changed a couple of things and the error went away and it works. Thanks
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
|