locked
TextBox Autocompletion RRS feed

  • Question

  • Hello

    I have a login form. I am trying to write AutoComplete code for the User Name TextBox.
    My requirement is....In the User Name TextBox  i enter renu once and logged in. And again logged out.

    Now if again when the form is displayed, as soon as i type 'r' it should automatically show all the words/Names starting with 'r' which i already entered before. How can i achieve this?.........Please Advise...Thanks in advance..

    I have written the following code. But it is not working for me. please guide me in the right direction...Thanks again...

    I have written this code in the form load event

    AutoCompleteStringCollection coll = new AutoCompleteStringCollection();

    for (int i = 0; i <= 10; i++)

    {

    coll.Add(String.Format("Custom String{0}",i));

    }

    textBox1.AutoCompleteCustomSource = coll;

    textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;

    textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;


    Please advise.....

    Thursday, March 19, 2009 8:06 PM

Answers

  •  If its not in the AutoCompleteList, i.e. a new entry, you wont get any match because its the first time its been encountered. So in the backend of the form, for example when the user hits the Submit button and triggers an event, check the contents of the TextBox and run a search through the current List. If it doesn't exist, add it to the List so that it shows up the next time.

    • Marked as answer by Kira Qian Thursday, March 26, 2009 6:00 AM
    Thursday, March 19, 2009 10:38 PM
  •  

    Hi renuami,

    I have written an similar sample before. The requirement of that case is want to auto complete all typed mail address.
    http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/e5543002-8624-4f5b-b9b2-a6969d66d3ec/

    In this example, when the focus leave the textbox, I will add that mail address to the list, when the form is close, all list items will be written to a txt file. The next time the form is load, it will read all text from txt file and use it to the AutoCompleteCustomSource of textbox.

    You can convert the code into C# use this tool.
    http://www.developerfusion.com/tools/convert/vb-to-csharp/

    Sincerely,
    Kira Qian


    Please mark the replies as answers if they help and unmark if they don't.
    • Marked as answer by Kira Qian Thursday, March 26, 2009 6:00 AM
    Monday, March 23, 2009 6:48 AM

All replies

  •  If its not in the AutoCompleteList, i.e. a new entry, you wont get any match because its the first time its been encountered. So in the backend of the form, for example when the user hits the Submit button and triggers an event, check the contents of the TextBox and run a search through the current List. If it doesn't exist, add it to the List so that it shows up the next time.

    • Marked as answer by Kira Qian Thursday, March 26, 2009 6:00 AM
    Thursday, March 19, 2009 10:38 PM
  •  

    Hi renuami,

    I have written an similar sample before. The requirement of that case is want to auto complete all typed mail address.
    http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/e5543002-8624-4f5b-b9b2-a6969d66d3ec/

    In this example, when the focus leave the textbox, I will add that mail address to the list, when the form is close, all list items will be written to a txt file. The next time the form is load, it will read all text from txt file and use it to the AutoCompleteCustomSource of textbox.

    You can convert the code into C# use this tool.
    http://www.developerfusion.com/tools/convert/vb-to-csharp/

    Sincerely,
    Kira Qian


    Please mark the replies as answers if they help and unmark if they don't.
    • Marked as answer by Kira Qian Thursday, March 26, 2009 6:00 AM
    Monday, March 23, 2009 6:48 AM