Click here to Skip to main content
Licence 
First Posted 26 Jan 2004
Views 81,486
Bookmarked 35 times

Autocomplete Textbox Control

By | 26 Jan 2004 | Article
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

About the Author

kelly123

Web Developer

United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMultiLine Bug [modified] PinmemberMANSATAN22:42 14 Aug '06  
QuestionHow i can make it work when close the Form PinmemberM.F14:43 2 Jul '06  
GeneralDemo application not working PinmemberDrew Noakes2:59 30 Mar '05  
GeneralEvents not firing PinsussAnonymous7:48 16 Jul '04  

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.

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