代码之家  ›  专栏  ›  技术社区  ›  Rob

数据绑定:ComboBox.Text在SelectedValue更改时不更新?

  •  1
  • Rob  · 技术社区  · 15 年前

    我有一个 ProbationComboBox SelectedValue 绑定到 RegistrationBindingSource DisplayMember 绑定到 ProbationBindingSource .

    当我打电话的时候 RegistrationBindingSource.ResetCurrentItem() , the 选择值 属性已使用来自的正确值刷新 RegistrationBindingSource.ProbationID() 但是 Text 属性未更新。

    以下是如何在组合框上设置数据绑定:

    ProbationComboBox.DataBindings.Add(New System.Windows.Forms.Binding( _
       "SelectedValue", Me.RegistrationBindingSource, "ProbationID", True))
    
    ProbationComboBox.DataSource = Me.ProbationBindingSource
    ProbationComboBox.DisplayMember = "probation"
    ProbationComboBox.ValueMember = "id"
    

    在我找出绑定的问题之前,我一直将此作为临时修复:

    DataRow row = CType(ProbationBindingSource.Current, DataRowView).Row
    ProbationComboBox.Text = CType(row, RootNamespace.DataSet.probationRow).probation
    

    有什么想法吗?谢谢!

    2 回复  |  直到 13 年前
        1
  •  1
  •   John    15 年前

    调用ResetBindings怎么样?

    帮助文件说这样做“会导致绑定到BindingSource的控件重新读取列表中的所有项并刷新其显示的值。”

        2
  •  1
  •   Rob    13 年前

    问题不在于数据绑定到 RegistrationBindingSource 但是我的数据和程序。以下是发生的事情:

    1. 我会清理 Text 所有属性 ComboBox 记录加载前的控件。

    2. ProbationBindingSource.Current 通过数据绑定或手动设置更新 ProbationComboBox.SelectedValue 财产。

    3. 在大多数情况下,学生不在试用期,而且 试用绑定源。当前 更新的值与以前相同。因此, ProbationBindingSource.Position 没有改变,而且 文本 属性未更新。

    我的最终解决方案检查 SelectedValue 将在清除 文本 属性。

    推荐文章