|
-
Aug 9th, 2007, 02:59 AM
#1
Thread Starter
Addicted Member
Autocomplete with seperator
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
-
Aug 9th, 2007, 10:45 PM
#2
Fanatic Member
Re: Autocomplete with seperator
Listen for the Enter event to save the current list then on the Leave event append all the list items together.
-
Aug 10th, 2007, 02:05 AM
#3
Thread Starter
Addicted Member
Re: Autocomplete with seperator
But how do i show the AutoComplete list that shows up underneath the textbox after each comma being typed?
-
Aug 10th, 2007, 08:36 PM
#4
Hyperactive Member
Re: Autocomplete with seperator
 Originally Posted by figa
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...
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 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);
}
Last edited by BramVandenbon; Aug 10th, 2007 at 09:12 PM.
____________________________________________
Please rate my messages. Thank you!
____________________________________________
Bram Vandenbon
http://www.bramvandenbon.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|