我无法通过自动完成功能恢复组合框的值和密钥。
我在访问表单后执行代码:
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);
}
如果我什么也没输入,只需向上和向下移动箭头即可。
如果我键入一些内容,它将无法正常工作。
组合框上没有其他事件。