Click here to Skip to main content
Click here to Skip to main content

Autocomplete Textbox Control

, 26 Jan 2004
Rate this:
Please Sign up or sign in to vote.
A textbox control that will complete what the user types. It allows the user to choose what to remember for autocompletion.

Introduction

This is a textbox control that will autocomplete what the user is typing in it. It uses a list of words that the user can create. It uses a text file to store the list. I have stored it this way to allow a user to easily edit the list with Notepad.

Background

I had a user who needed to enter data that was often the same, but every once in a while changed. The application consisted mostly of textboxes and the user wanted to keep it that way, instead of having some combo controls thrown in. Sometimes they wanted to be able to add an item to the list, such as a new company that they were dealing with.

I could have stored the data in the registry or a database, but decided on a text file to allow the user to easily edit it.

Using the code

Just add the control to the toolbox by browsing to the DLL. Then drag and drop the control to your form. The code consists of one class, senseControl2, which inherits from TextBox. I have added a few properties to the TextBox control. The ChoiceFile property lets you name a file to store the choices in. You can use the same file for more than one control and keep them in sync with the ChoicesSaved event. The ChoicesSaved event is raised whenever the user saves a new item. You can use code similar to this in the event handler:

private void senseControl_ChoicesSaved(object sender, System.EventArgs e)
{
    if(sender == this.senseControl1)
        this.senseControl2.ReloadChoices();
    else
        this.senseControl1.ReloadChoices();
}

You do not need to assign a filename, the control will default to the control's name with a .txt suffix. Also you may pre-set some values by using the Choices property. This will create a text file with these items, the first time a user saves a new item.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

kelly123
Web Developer
United States United States
No Biography provided

Comments and Discussions

 
GeneralMultiLine Bug [modified] PinmemberMANSATAN14-Aug-06 23:42 
QuestionHow i can make it work when close the Form PinmemberM.F2-Jul-06 15:43 
hello,thanks for your Autocomplete Textbox Control but
i want it to save what had written in it when the user close the form automatically
thx
GeneralDemo application not working PinmemberDrew Noakes30-Mar-05 3:59 
GeneralEvents not firing PinsussAnonymous16-Jul-04 8:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 27 Jan 2004
Article Copyright 2004 by kelly123
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid