我试图根据Sorteddictionary
中存储的值在组合框中选择项目
字符串值匹配
comboBoxEdit3.SelectedItem = comboBoxEdit3.FindStringExact(Queries[_ucSetting.StandardSearchID.ToString()] + "(" + _ucSetting.StandardSearchID.ToString() + ")");
组合框中的元素
但这会在ComboBox中产生空选择
答案 0 :(得分:1)
FindStringExact仅返回与您的字符串匹配的 first 项的索引;如果找不到匹配项,则返回-1。您正在尝试将 SelectedItem 设置为要返回的索引。您应改为设置 SelectedIndex :
comboBoxEdit3.SelectedIndex = comboBoxEdit3.FindStringExact(Queries[_ucSetting.StandardSearchID.ToString()] + "(" + _ucSetting.StandardSearchID.ToString() + ")");