【问题标题】:Combobox selection based on FindStringExact not working as intended基于 FindStringExact 的组合框选择未按预期工作
【发布时间】:2019-08-13 10:41:04
【问题描述】:

我正在尝试根据Sorteddictionary 中的存储值选择组合框中的项目

字符串值匹配

  comboBoxEdit3.SelectedItem = comboBoxEdit3.FindStringExact(Queries[_ucSetting.StandardSearchID.ToString()] + "(" + _ucSetting.StandardSearchID.ToString() + ")");

ComboBox 中的元素

但这会在组合框中产生空选择

【问题讨论】:

    标签: c# .net dictionary combobox sorteddictionary


    【解决方案1】:

    FindStringExact 仅返回与您的字符串匹配的 first 项的索引,如果未找到匹配项,则返回 -1。您正在尝试将 SelectedItem 设置为要返回的索引。您应该改为设置 SelectedIndex

    comboBoxEdit3.SelectedIndex = comboBoxEdit3.FindStringExact(Queries[_ucSetting.StandardSearchID.ToString()] + "(" + _ucSetting.StandardSearchID.ToString() + ")");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-18
      • 2020-07-14
      • 2016-05-06
      • 2019-11-03
      • 1970-01-01
      • 1970-01-01
      • 2012-07-29
      相关资源
      最近更新 更多