Results 1 to 9 of 9

Thread: Making a listbox highlight items as you type?

Threaded View

  1. #9
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Making a listbox highlight items as you type?

    If you make a hidden textbox (outside the screen with visible set to true), then use something like this, you can kinda make it work. I guess you'll need to add a timer to remove the text in the textbox after a second or so to make it function a bit better.
    Code:
            public Form1()
            {
                InitializeComponent();
                listBox1.MouseUp += new MouseEventHandler(listBox1_MouseUp);
                textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
            }
    
            void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar == (char)Keys.Back)
                {
                    textBox1.Text = "";
                }
            }
    
            void listBox1_MouseUp(object sender, MouseEventArgs e)
            {
                textBox1.Focus();   
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
                if (textBox1.Text != "")
                {
                listBox1.SelectedIndex = listBox1.FindString(textBox1.Text);
                }
            }

    Edit: Updated code slightly
    Last edited by Andrew G; Aug 6th, 2008 at 10:53 AM.

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