Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Suggestish text box (autocomplete)

What would be the best way to develop a text box that remembers the last x number of entries that were put into it. This is a standalone app written with C#.

like image 958
Ethan Gunderson Avatar asked Sep 04 '08 01:09

Ethan Gunderson


People also ask

How do I get predictive text on Google?

Click Search features from the menu on the left and then click the Autocomplete tab. Click on the slider to set Enable autocomplete to On. It can take up to 2-4 days for autocompletions tailored to your search engine to start appearing.

How does Google Instant Autocomplete suggestions work?

Autocomplete predictions reflect real searches that have been done on Google. To determine what predictions to show, our systems look for common queries that match what someone starts to enter into the search box but also consider: The language of the query. The location a query is coming from.

How do I turn off suggested Autofill?

Click on "Settings." Choose "Privacy & Security." In the "Forms and Autofill" section uncheck the options for which you wish to disable Autofill. The system will automatically save your settings.


1 Answers

This is actually fairly easy, especially in terms of showing the "AutoComplete" part of it. In terms of remembering the last x number of entries, you are just going to have to decide on a particular event (or events) that you consider as an entry being completed and write that entry off to a list... an AutoCompleteStringCollection to be precise.

The TextBox class has the 3 following properties that you will need:

  • AutoCompleteCustomSource
  • AutoCompleteMode
  • AutoCompleteSource

Set AutoCompleteMode to SuggestAppend and AutoCompleteSource to CustomSource.

Then at runtime, every time a new entry is made, use the Add() method of AutoCompleteStringCollection to add that entry to the list (and pop off any old ones if you want). You can actually do this operation directly on the AutoCompleteCustomSource property of the TextBox as long as you've already initialized it.

Now, every time you type in the TextBox it will suggest previous entries :)

See this article for a more complete example: http://www.c-sharpcorner.com/UploadFile/mahesh/AutoCompletion02012006113508AM/AutoCompletion.aspx

AutoComplete also has some built in features like FileSystem and URLs (though it only does stuff that was typed into IE...)

like image 142
Adam Haile Avatar answered Oct 01 '22 00:10

Adam Haile