Results 1 to 4 of 4

Thread: Autocomplete with seperator

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    198

    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

  2. #2
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    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.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    198

    Re: Autocomplete with seperator

    But how do i show the AutoComplete list that shows up underneath the textbox after each comma being typed?

  4. #4
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502

    Re: Autocomplete with seperator

    Quote 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
  •  



Click Here to Expand Forum to Full Width