views:

510

answers:

2

This is the relevant designer code for the ComboBox:

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

The problem is that when I call RegistrationBindingSource.ResetCurrentItem(), the SelectedValue property is refreshed with the correct value from RegistrationBindingSource.ProbationID(); However, the Text property is not updated.

Until I can figure out the problem with my binding, I've been doing this as a fix:

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

Any ideas? Your assistance is appreciated!

A: 

What about calling ResetBindings?

The help files say that doing this "causes a control bound to the BindingSource to reread all the items in the list and refresh their displayed values."

John at CashCommons
I tried this, with no luck. I even tried passing True for the argument, to force the schema to be re-read, but it didn't help.
Rob
+1  A: 

The problem was not with data-binding to the RegistrationBindingSource, but with my data and procedures. Here's what was happening:

  1. I clear the Text property of all ComboBoxes before a record load

  2. ProbationBindingSource.Current is updated, either by data binding or by manually setting ProbationComboBox.SelectedValue

  3. In 98% of cases, students are NOT on probation, and so the value of ProbationBindingSource.Current is updated with the same value as before. As a result ProbationBindingSource.Position doesn't change, and the Text property is not updated.

My final solution simply checks if a given SelectedValue is going to be updated before clearing a ComboBox's Text property.

Rob