Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
C# combobox (search anywhere within list, not just first letter autocomplete) using with windiows form applicaiton
Posted
Comments
David_Wimbley 14-Jan-13 23:19pm    
What list are you talking about? A list box control list? The list of items that pops open when you type in a combo box?

Hi,

In WPF[^]
In Windows[^]
 
Share this answer
 
C#
private void comboBox1_KeyUp(object sender, KeyEventArgs e)
        {
            //index of taped text
            int index;
            //text found
            string found;
            //text written
            string actual;

            //to avoid these keys
            bool bo = e.KeyCode == Keys.Back || e.KeyCode == Keys.Left
            || e.KeyCode == Keys.Right || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down
            || e.KeyCode == Keys.Delete || e.KeyCode == Keys.PageDown
            || e.KeyCode == Keys.PageUp || e.KeyCode == Keys.End
            || e.KeyCode == Keys.Home;

            if (bo == true)
                return;

            actual = this.comboBox1.Text;
            index = this.comboBox1.FindString(actual);

            //this condition means that there is a result
            if (index > -1)
            {
                found = this.comboBox1.Items[index].ToString();
                this.comboBox1.SelectedIndex = index;

                this.comboBox1.SelectionStart = actual.Length;
                this.comboBox1.SelectionLength = found.Length;
                this.comboBox1.DroppedDown = true;

            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900