Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find as you type in C#

Tags:

c#

.net

Im trying to emulate a 'find as you type' function like that of the address bar ("awesome bar") in FireFox. I want a suggestion box to appear below a textbox, and the suggestion box contains strings that contain what is in the textbox. I looked at the autocomplete feature of a normal WinForms textbox, but it seems to only search the beginning of the strings.

Has anyone here built or have experience with implementing something like this?

edit: Some clarification- It is a WinForms project. It needs to search inside a string, not just the beginning (which is what a normal textbox does if i recall correctly). And the suggestions should be displayed in a popup like a textbox autocomplete.

like image 310
Mike_G Avatar asked Dec 30 '22 19:12

Mike_G


2 Answers

You need to handle the TextChanged event for your text entry field, and when the text changes, start a new thread running that will apply the new search. If the text changes before you get your results back, just kill the thread. If the thread returns results in time, display them.

You can get slightly more advanced (e.g. wait for a short time after the text changes so that the user can type a word without you triggering off loads of useless threads) but essentially that's it.

like image 194
Jason Williams Avatar answered Jan 10 '23 17:01

Jason Williams


There was a discussion earlier on this topic where the author concluded that you are better off doing the whole thing yourself.

How can I dynamically change auto complete entries in a C# combobox or textbox?

like image 32
SolutionYogi Avatar answered Jan 10 '23 18:01

SolutionYogi