Board index » delphi » Auto-completion in a drop down listbox

Auto-completion in a drop down listbox

Hello form Denmark

Can anybody help me with delphi 4.0 code that makes auto-completion in a
drop down listbox.
If I write "Ste" the auto-completion will fill in "Steffen Kristensen" from
the items in the drop down listbox.
Any help is appriciated

Regards
Steffen Kristensen

 

Re:Auto-completion in a drop down listbox


Hi Steffen,

What you're looking for is called incremental searching for the drop
down box.  Basically you have to capture the keystrokes of the user and
after a certain amount of time set by a timer when no more keys have
been pressed, look through the drop down list for text that matches the
characters already typed in.

You might want to look into a combo box that already has this feature
like our combo boxes.

--
Earl Reddell
Res-cue(Resourceful Components for User Ease!)
Check out our web site: http://www.res-cue.com

--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---

Re:Auto-completion in a drop down listbox


Quote
>What you're looking for is called incremental searching for the drop
>down box.  Basically you have to capture the keystrokes of the user and
>after a certain amount of time set by a timer when no more keys have
>been pressed, look through the drop down list for text that matches the
>characters already typed in.

A better way to do it is to search the combobox EVERY keystroke, and
then make a selection part of the text that you completed the users input
with.When the user continues to write the auto-added text disapears and
then we do a new search...

LB Cid

Re:Auto-completion in a drop down listbox


Hi LB Cid,

Quote
> A better way to do it is to search the combobox EVERY keystroke, and
> then make a selection part of the text that you completed the users
input
> with.When the user continues to write the auto-added text disapears
and
> then we do a new search...

I agree with you that your suggestion is an effective way of performing
an incremental search but it is not efficient. Let me explain.

In my opinion, it is better that fewer searches are performed than
performing a search on every character. For example, if the user is a
fast typer, they could be annoyed by having to wait for the search to be
performed every time they type a key when there are alot of items to
search through.  By having a timer set to say 1/3 second or 1/2 second
after the user has released the key(KeyUp) the user is able to type as
many characters as they wish until they have paused for the time frame
in which the search would be fired. If the user waits more than the 1/3
second the search is fired.  But if the user types another character
before the time has expired the timer is turned off until the key is
released.  If the user types in characters that do not exist with in the
order of the item list then once they have stopped for the time frame
those characters are removed and the item that most closely matches the
text is selected.

This involves performing the search from the begining of the text to the
current position of the caret and comparing it to the text of the items
in the list up to the same number of characters.  If there is no match,
the text is searched in reverse order until characters can be found that
make a match and the caret is positioned respectively.  This also avoids
the flickering caused by selecting and removing the text from the last
cursor position to the end of the found text in the edit box.

I admit the above is more complicated to code but it is both efficent
and effective.  If a developer could be sure that there would never be a
large number of items to search through, then I would agree that your
method would be better if not easier to write.

regards,
--
Earl Reddell
Res-cue(Resourceful Components for User Ease!)
Check out our web site: http://www.res-cue.com

--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---

Re:Auto-completion in a drop down listbox


Quote
>I admit the above is more complicated to code but it is both efficent
>and effective.  If a developer could be sure that there would never be a
>large number of items to search through, then I would agree that your
>method would be better if not easier to write.

I do a serach in a Btrieve database, on every keystroke. The database
holds about 100,000 articles. And it doesnt slow down anything...

LB Cid

Other Threads