views:

488

answers:

2

I'm looking for a library for Autocomplete support in text controls which remembers all previous entries of the user and provide auto-complete support for it.

For example for "recent files" I use http://www.genghisgroup.com/ and it works great. Do you know something like that for this purpose?

UPDATE : This is a .NET Winforms application and I'm using normal Text Control.

A: 

Download the source code and look at recent files. No doubt it is storing to some form of persistant store (database, file, etc) and using that information to fill in the list. You just dupe the functionality and make it for a TextBox that is focused on words instead of files.

I have not looked at the Genghis source, but I am sure it is easy enough to run through the control you use that has similar functionality and dupe it. When you do this, contact the Genghis group and offer it as a submission. That is how we support open source.

Gregory A Beamer
+1  A: 

Built into a .NET TextBox is AutoComplete functionality. First you set the AutoCompleteMode property (Suggest, Append, etc.), and then you choose the AutoCompleteSource. Your choices for that are:

FileSystem HistoryList RecentlyUsedList AllUrl AllSystemSources FileSystemDirectories CustomSource None ListItems

In your case, you'd use CustomSource, and then populate the AutoCompleteCustomSource Collection that's a property on the TextBox. I would suggest to have a simple SqlCe database, to where you can store the values the user has entered in the past, and then when the app loads, retrieve those values, and populate the AutoCompleteCustomSource.

A quick code sample:

private void button1_Click(object sender, EventArgs e)
{
    this.textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
    this.textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;

    string[] items = GetListForCustomSource();
    this.textBox1.AutoCompleteCustomSource.AddRange(items);

}

private string[] GetListForCustomSource()
{
    var result = new List<string>();

    foreach(var value in Enum.GetNames(typeof(DayOfWeek)))
    {
        result.Add(value);
    }

    return result.ToArray();
}

I jsut used DayOfWeek as an example, but you can query a database in that method, and return the results.

BFree
I'll give it a try. What about storing them in "Application Settings"? That should do for the last 20 entry or so.
dr. evil
Oh, if you only want to store 20 or so, then yes, you don't need a full db for that. Application Settings, or just a regular XML file will do just fine.
BFree