|
-
Nov 11th, 2000, 09:17 AM
#1
Thread Starter
Member
I have a listbox sorted alphabetically, with a text box above. What I want to do is allow the user to type in a search in the text box and as they type the list box selection changes gradually.
E.g if my list is
Arsenal
Chelsea
Man City
Man United
as the user types 'M' it moves to Man City and then stays there unless they type 'an u' which then changes the list to man united.
any ideas?
-
Nov 11th, 2000, 10:16 AM
#2
transcendental analytic
Are you really sure you want to do it that way? The search box will contain "Mu" not "Man U" i could make you a fast binary searh if you want.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 11th, 2000, 10:30 AM
#3
Thread Starter
Member
my list has about 350 items and i want the user to type in a search and the list moves to the nearest item
-
Nov 11th, 2000, 10:51 AM
#4
transcendental analytic
Here goes, this binary search should find you as fast as possible, remove the lcases if you want case sensistive search.
Code:
Private Sub Text1_Change()
List1.ListIndex = BinarySearch(Text1.Text, List1)
End Sub
Function BinarySearch(Byval str As String, list As ListBox)
Dim x&, l&, temp$
str = lcase(str)
l = List1.ListCount / 2
x = l
Do
temp = lcase(list.list(x))
If str = temp Then
Exit Do
ElseIf str > temp Then
l = l / 2
x = x + l
Else
l = l / 2
x = x - l
End If
Loop While l
BinarySearch = x
End Function
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
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
|