C#组合框在自动完成中获取键和文本

C#组合框在自动完成中获取键和文本,c#,list,dictionary,combobox,autocomplete,C#,List,Dictionary,Combobox,Autocomplete,我在使用autocomplete恢复组合框的值和键时遇到问题 我在访问表单时执行代码: Dictionary<string, string> comboSource = new Dictionary<string, string>(); foreach (int i = 0; i < products.Rows.Count; i++) { comboSource.Add(dr["id"].ToString(), dr["name"].ToString());

我在使用autocomplete恢复组合框的值和键时遇到问题

我在访问表单时执行代码:

Dictionary<string, string> comboSource = new Dictionary<string, string>();

foreach (int i = 0; i < products.Rows.Count; i++)
{
  comboSource.Add(dr["id"].ToString(), dr["name"].ToString());
}

autoCompleteCombo.DataSource = new BindingSource(comboSource, null);
autoCompleteCombo.DisplayMember = "Value";
autoCompleteCombo.ValueMember = "Key";
autoCompleteCombo.AutoCompleteSource = AutoCompleteSource.ListItems;


private void autoCompleteCombo_SelectedIndexChanged(object sender, EventArgs e)
{
    string key = ((KeyValuePair<string, string>)autoCompleteCombo.SelectedItem).Key;
    string value = ((KeyValuePair<string, string>)autoCompleteCombo.SelectedItem).Value;

    MessageBox.Show(key + " / " + value);
} 
Dictionary comboSource=newdictionary();
foreach(int i=0;i
如果我不键入任何内容,只需向上和向下移动箭头即可

如果我键入某个内容,它将不起作用


组合框上没有其他事件。

键入时,用户可以从列表中筛选一个或多个项目。用户必须按
Enter
或从列表中选择一项(使用光标或鼠标)来触发
SelectedIndexChange
(或
SelectionChangeCommitted
)事件。这是标准行为。我想大多数人已经习惯了。谢谢你的回复。