I have a user control that contains several text boxes bound to a bindingSource. I want to drop that user control onto another form and pass the datasource to the control to use.
I have tried making the user control's bindingSource public and setting it to the same bindingSource on the form,
List<Person> data = MyGetData(); // returns a list of people
this.formControl.bindingSource.DataSource = data; // where formControl is my user control containing bound text boxes.
inside my user control I have a textbox called textboxFirstName, and a bindingsource called bindingSource
Using the designer, I set bindingSource.DataSource to be Person where Person is one of my domain classes.
Also using the designer I set textboxFirstName.DataBindings.Text to "bindingSource - FirstName" by picking it from the list of Person properties.
There is no error message, but the text box is not displaying the data.
[Update] I can get the binding working if I create the following procedure and call it.
public void SetBinding(BindingSource bs)
{
this.bindingSource = bs;
this.firstNameTextBox.DataBindings.Clear();
this.firstNameTextBox.DataBindings.Add(new Binding("Text", bs, "firstName"));
}
However I am wondering why setting the binding source alone is not enough.
Note at design time I had set the user control's bindingSource DataSource to People. This enabled me to pick the text box's DataBindings.Text property from a list.