c#ComboBox将项添加为用户类型文本

时间:2016-07-19 10:07:18

标签: c# combobox

需要适当的解决方案:

  1. ComboBox中的用户类型。
  2. 每个字母都会输入一个匹配名称列表,从互联网返回。
  3. ComboBox下拉列表中的项目和文本在comboBox中保持不受影响。
  4. 我的代码:

        private void InitializeComboBoxSearchSymbol()
        {
            comboBoxSearchName.ValueMember = "first_name";
            comboBoxSearchName.DisplayMember = "first_name";
            comboBoxSearchName.AutoCompleteMode = AutoCompleteMode.None;
            comboBoxSearchName.SelectedIndexChanged += comboBoxSearchName_SelectedIndexChanged;
            comboBoxSearchName.KeyDown += SearchNameTextChanged;
        }
    
    
        private void comboBoxSearchName_SelectedIndexChanged(object sender, EventArgs e)
        {
    
        }
    
        private void SearchNameTextChanged(object sender, KeyEventArgs e)
        {
            YahooData yd = new YahooData();
            List<Name> listNames = yd.YahooNameLookup(comboBoxSearchName.Text);
            comboBoxSearchName.Items.Clear();
            comboBoxSearchName.Items.AddRange(listNames.ToArray());
        }
    

    上面的代码有效,但是列表没有被删除,文本光标变得怪异,有时会抛出错误。

1 个答案:

答案 0 :(得分:0)

以编程方式打开Win Forms组合框:

comboBoxSearchName.DroppedDown = true;