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.