【问题标题】:ComboBox got new SelectedValue on SelectionChangeCommitted but doesn't got new SelectedTextComboBox 在 SelectionChangeCommitted 上获得了新的 SelectedValue,但没有获得新的 SelectedText
【发布时间】:2012-10-10 09:17:39
【问题描述】:

我有这个代码

private void FrmNovedadMedidas_SelectionChangeCommitted(object sender, EventArgs e)
        {
            ComboBox c = (ComboBox)sender;
            CargarMedidasPorIdTipoMedida(Convert.ToInt16(c.SelectedValue));
            this.txtBoxNombreTipoMedida.Text = c.SelectedText;
        }

c.SelectedValue 中获得了选择的新值(用户在组合中选择的值)。 但是在c.SelectedText 中,我得到了 ComboBox 的旧值(我的意思是,在用户更改选择之前的那个值)。

是否有任何属性可以给我新的选定文本? 我想避免每次都在绑定到 ComboBox 的 DataSet 中进行搜索。

我已阅读 this 但不起作用,我在 ComboBox 中没有 CommitEdit()

编辑:

c.Text 也给了我旧的

【问题讨论】:

  • 我似乎记得这种情况与 ComboBox 的 DropDownStyle 有关。您能否尝试不同的样式,看看 Text 属性是否设置为 SelectionChangeCommited 中的新值?
  • 使用 DropDownList 解决了这个问题,也解决了我正在检查的另一个问题。非常感谢 !!请将其发布为答案,以便我接受它

标签: c# .net winforms combobox selectedindexchanged


【解决方案1】:

c.SelectedValue() 为我返回 null

c.GetItemText(c.SelectedItem) 虽然对我有用。更改下拉样式不是一种选择。

【讨论】:

    【解决方案2】:

    尝试 ComboBox 上的 SelectedIndexChanged 事件与 SelectionChangeCommited 事件。然后使用c.Text获取用户刚刚选择的值。

    【讨论】:

    • 问题是,在这种情况下,即使以编程方式选择更改也会触发,我想避免这种情况
    【解决方案3】:

    我似乎记得这种情况与 ComboBox 的 DropDownStyle 有关。

    您能否尝试不同的样式,看看 Text 属性是否设置为 SelectionChangeCommited 中的新值?

    根据您的评论,似乎使用 DropDownList 样式可以解决问题。

    干杯

    【讨论】:

      【解决方案4】:

      我发现了一些东西。

      c.GetItemText(c.SelectedItem)
      

      是否有直接属性,请发布。 无论如何感谢您的自述文件。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-19
        • 1970-01-01
        • 1970-01-01
        • 2018-04-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多