views:

205

answers:

1

I need to create a text box which will auto resolve what the user types based on a list of values, something similar to the "To" field in e-mail clients.

For example, my list has these values:

Car House Tree

Typing "hou" would automatically resolve to "House", and trying to delete a single letter (with backspace or delete) of that word would delete it entirely, also it would not allow one to mess with an already resolved word (for example "Hou[something]se").

Of course I could create this using a regular text box and controlling what is typed and keeping a strucure with the resolved words..... there are a lot of exceptions to deal with, though, and I'm not willing to reinvent the wheel. Has anyone implemented something like that before? Is there any control in visual studio that provides something similar to what I described?

Update

Note that I understand that the regular text box supports autocompletion, but besides autocompletion I need autoresolution, wich is a different concept...

+2  A: 

The standard TextBox control already supports this via the AutoCompleteSource, AutoCompleteMode, and AutoCompleteCustomSource properties.

You can select a standard complete source using AutoCompleteSource or you can specify a custom list, and then provide an AutoCompleteStringCollection object to the AutoCompleteCustomSource property. Although I haven't tried it, I suspect that this is not quite as flexible as the Win32 variation on this where you can dynamically provide auto-complete results based on what has been typed so far, but you may be able to mimic this by overriding AutoCompleteStringCollection.

Update

This answer was provided before the question changed to indicate the OP already was aware of this information.

Jeff Yates
Thanks, Jeff, but that will only autocomplete, right? It won't resolve the words.... I mean, if I try to delete a word, I will have to delete every single letter, for example..... as I said, what I need is a control similar to the "To" field in MS Outlook...
Sam
No, it should resolve words depending on the mode you select.
Jeff Yates
To resolve the words to some other entity you are definitely going to need to add your own functionality.
Jeff Yates