views:

49

answers:

1

I have this in my form's designer code:

this.referenceNumberTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.clientDetailBindingSource, "ClientDetails.ReferenceNumber", true));

In a method in the form just before it gets displayed I say

this.clientDetailBindingSource = passedInBindingSource;

The controls that are databound to this.clientDetailBindingSource do not show any data.

I have also tried doing ResetBindings() but nothing happened.

+1  A: 

the textbox's DataBindings contains a Binding object that references the original binding source; reassigning the form's data member does not alter the Binding object already created

in other words, the textbox's binding is still bound to the old binding source

unless you're performing this assignment before the call to InitializeComponent in the form's constructor...?

Steven A. Lowe
I am changing the bindingsource that the control is bound to though so the control should reflect the changes
Jon
@[Jon]: no, you're not; you just think you are! ;-) InitializeComponent creates the Binding objects which tie the controls to the whatever the bindinsource object is at that instant. Changing the bindingsource object on the form later does not magically alter the Binding objects already created.
Steven A. Lowe
Can I change the bindingsource in the existing binding object without doing a remove/add?
Jon
@[Jon]: unfortunately not - DataSource is a read-only property in the Binding class.
Steven A. Lowe