Click here to Skip to main content
15,843,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have simple combobox and trying to search items in the dropdown list without filtering. When I upload the text it should highlight the best guess (the one which starts with the letter in the cmbtext etc.). For example there are 'ABC' and 'DEF' when I press A it should just highlight 'ABC'.

How can I achieve this.

What I have tried:

protected override void OnTextUpdate(EventArgs e)
    DroppedDown = true;
    searchText = Text;

    SelectedIndex = findIndex(Text);
    Text = searchText; //when dropdown occurs it automatically select an item and writes it in the text place. To prevent this I just update the text
    SelectionStart = Text.Length;

private int findIndex(string text)
    for (int i = 0; i < dataTable.Rows.Count; i++)
        if (dataTable.Rows[i][1].ToString().ToUpper().StartsWith(text.ToUpper()))
            return i;

    return -1;

The code I thought should workd is here. It just blinks the text and then highlight is gone.
Comments 1-Aug-22 7:50am    
There is an article about this:
Member 15700998 1-Aug-22 11:48am    
Thank you for your comment. This one it might help actually for a reference. But it uses suggestion box which is a popup when you type something. In my case I am using real dropdown menu. The reason is I am making some drawings.

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

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