How to disable combox dropdown when user enters text into the combox

I have a simple combobox in c# forms which is populated from an array.

I have set AutoCompleteMode to SuggestAppend and AutoCompleteSource to ListItems. This allows me to filter through the list quickly by typing a string into the combobox and matching items are displayed as I type along. This works great.

However, when the drop down list is open and I start typing, the filtered list appears on top of the dropdown list but I cannot select from the filtered list but only from the drop down.

How to disable drop down list while open as soon as user enters a character into the combobox.

Currently only have one method for the combobox

private void SelectJobDropdown_SelectedIndexChanged(object sender, EventArgs e)
        {
            //plenty of code here 
        }

I have tried adding other methods for the combobox such as KeyPress or Keydown but none seems to be working for as I'm very likely doing something wrong

Using Visual Studio 2015


If I understood you correctly you don't like the overlapping list over the old drop down. Since you type letters into the ComboBox I would suggest to use the comboBox1_TextUpdate event. This nice line of code should fix your problem:

private void comboBox1_TextUpdate(object sender, EventArgs e)
{
    comboBox1.DropDownStyle = ComboBoxStyle.Simple;

Setting the ComboBox.DropDownStyle property, which

specifies whether the list is always displayed or whether the list is displayed in a drop-down[...]

to ComboBoxStyle.Simple, which

Specifies that the list is always visible and that the text portion is editable. This means that the user can enter a new value and is not limited to selecting an existing value in the list.

will remove the original dropdown (long list) and only the filtered results remain.

链接地址: http://www.djcxy.com/p/60908.html

上一篇: 将两个列表绑定到组合框,其中一个仅用于提示

下一篇: 当用户将文本输入到combox中时如何禁用combox下拉菜单