Like the Gmail To Field, i would like to add a saved email adress after each comma pressed.
I have a AutoCompleteCustomSource, and i would like to append saved strings to a textbox.
Any idea which way to go?
Thnx, Figa
Printable View
Like the Gmail To Field, i would like to add a saved email adress after each comma pressed.
I have a AutoCompleteCustomSource, and i would like to append saved strings to a textbox.
Any idea which way to go?
Thnx, Figa
Listen for the Enter event to save the current list then on the Leave event append all the list items together.
But how do i show the AutoComplete list that shows up underneath the textbox after each comma being typed?
You could use a ComboBox instead of a TextBox...Quote:
Originally Posted by figa
Or you can use a ContextMenu! (which looks like the popup you get when you presses the right mouse button)
I would give the contextmenu a try ...
It's not that hard to use if you use a nested function. This works fine on my computer ! :)
Here's the full code ! Enjoy, and don't forget my reputation if you are happy about it :p lol :-D
Code:private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == ';')
{
ContextMenu m = new ContextMenu();
m.MenuItems.Clear();
m.MenuItems.Add(CreateMenuItem(m, "item1", textBox1));
m.MenuItems.Add(CreateMenuItem(m, "item2", textBox1));
m.MenuItems.Add(CreateMenuItem(m, "item3", textBox1));
m.MenuItems.Add(CreateMenuItem(m, "item4", textBox1));
m.Show(textBox1, new Point(0, SomeTextBox.Height));
}
}
private MenuItem CreateMenuItem(ContextMenu m, String itemText, Control SomeTextBox)
{
// a nested function ! cool huh ;-)
EventHandler handler = delegate(object a, EventArgs b)
{
SomeTextBox.Text += itemText;
};
return new MenuItem(itemText, handler);
}