Click here to Skip to main content
13,251,998 members (50,541 online)
Click here to Skip to main content
Add your own
alternative version


36 bookmarked
Posted 26 Jan 2004

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.


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.


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)

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.


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


About the Author

Web Developer
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralEvents not firing Pin
Anonymous16-Jul-04 8:48
sussAnonymous16-Jul-04 8:48 

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

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

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