0

How can I make autocomplete TextBox that suggests each word while typing? For example, if the input is d, suggestions should be dog and dig. when dog is selected and space/enter is pressed, user continues to type and types j. Then new suggestions should be jump, jane, job etc. How can I implement that?

nicks
  • 2,161
  • 8
  • 49
  • 101
  • 1
    So you want a Autocomplete textbox? – Ivan Crojach Karačić Jun 07 '13 at 08:57
  • 1
    [WinForms | C# | AutoComplete in the Middle of a Textbox?](http://stackoverflow.com/questions/1437002/winforms-c-sharp-autocomplete-in-the-middle-of-a-textbox) – Ilya Ivanov Jun 07 '13 at 08:57
  • 1
    Follow this thread http://stackoverflow.com/questions/1357853/autocomplete-textbox-control – bangoo Jun 07 '13 at 08:58
  • What have you tried? Do you really need to implement this as it's sounds like an autocomplete box which, there are surely a number of existing implementations and third party scripts for? – Stokedout Jun 07 '13 at 09:00

2 Answers2

4

WindowsForms TextBox already has a auto complete feature:

    textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
    textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
    textBox1.AutoCompleteCustomSource.AddRange(new string[] { "dog","dig", "jump","jane","job"});

See MSDN for detailed information.

  • This is the simplest way of implementing auto complete, but as far as I can see, it does not support multiple words...only the first. – Matthew Layton Jun 07 '13 at 09:19
  • It shows you a list of matching words in the dictionary if this is the support of multiple words you mean. –  Jun 07 '13 at 09:31
  • I copied your example into a unit test and typed; "dog". Sure enough, it showed up an auto complete list for all words beginning with "d", but then I tried to type "j" after "dog", and no auto complete list showed up. – Matthew Layton Jun 07 '13 at 10:16
  • As long as there is no word starting with "dj" in your autocomplete list for sure nothing will be shown. –  Jun 10 '13 at 06:58
0

The following link shows a great example of this . . . http://www.codeproject.com/Tips/737799/IntelliSense-TextBox-in-Csharp