【问题标题】:Combobox binding does not update组合框绑定不更新
【发布时间】:2016-10-31 16:45:44
【问题描述】:

我正在尝试将组合框绑定到我使用绑定导航器导航的数据集中的值。

我有一个表单,以及一些通过绑定导航器绑定到数据集的文本框。

绑定到文本框很简单:

this.catActualTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myBindingSource, "CatActual", true))

效果很好,但我需要用组合框更改其中一个文本框。文本框显示数字(键),我想显示相关的描述(值)。所以我使用组合框。我用 DataTable 加载组合框,其中有两个列“IdCatActual”(键)和“Descript”(值)。它在表单中正确显示,但导航时不更新:

this.catActualComboBox1.DataSource = myDataTable;
this.catActualComboBox1.DisplayMember = "Descrip";
this.comboBox1.DataBindings.Add(new System.Windows.Forms.Binding("SelectedItem", this.myBindingSource, "CatActual"));

【问题讨论】:

    标签: c# data-binding combobox


    【解决方案1】:

    我终于得到了答案。

    我使用了错误的属性。我必须绑定“SelectedValue”属性而不是“SelectedItem”属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-04
      • 2013-04-17
      • 1970-01-01
      • 2015-12-17
      • 1970-01-01
      • 1970-01-01
      • 2016-02-22
      • 1970-01-01
      相关资源
      最近更新 更多