WinForms ComboBox DropDown and Autocomplete window both appear

后端 未结 10 1263
礼貌的吻别
礼貌的吻别 2020-12-05 17:41

I\'ve got a ComboBox on a winforms app with this code:

comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource         


        
相关标签:
10条回答
  • 2020-12-05 18:17

    Add a single line of code to your ComboBox KeyDown event and the problem is solved!

    private void comboBox_NameAndID_KeyDown(object sender, KeyEventArgs e)
    {
        comboBox_NameAndID.DroppedDown = false;
    }
    

    Source

    0 讨论(0)
  • 2020-12-05 18:18

    That's weired. Your code looks fine to me and I used this the AutoComplete feature a several times and it didn't show both the DropDown and the AutoComplete list.

    My suggestion would be

    • Set the DataSource after the Display/Value Members. I can't remember why but the other caused some problems.

      comboBox1.ValueMember = "ID";
      comboBox1.DisplayMember = "Display";
      comboBox1.DataSource = t;
      
    • Set the AutoCompleteSource at the end of your code (after adding the DataSouce)

    Maybe that helps.

    0 讨论(0)
  • 2020-12-05 18:18

    to only have one open at a time you can use comboBox1.Droppeddown = true open up the regular, false the AutoComplete will only appear

    0 讨论(0)
  • 2020-12-05 18:21

    No problem getting a repro for this simply by setting the properties from the PropertyGrid. Behaves this way both in Win7 and Windows XP.

    This is broken behavior documented in this feedback article. As indicated, Microsoft is not considering a fix. One possible workaround is to disable autocomplete in a DropDown event handler and re-enable it in a DropDownClosed event handler.

    0 讨论(0)
提交回复
热议问题