binding two BindingSources
-
21 august 2005 09:41I have two user controls. Each control has internaly a BindingSource.
I want that these two controls will be syncronized - will share the same data source and position.
How can i do that ?
Thanks
Asaf
Toate mesajele
-
21 august 2005 16:22
Ideally, you would pass the same BindingSource into both UserControls. That's not possible (easy) if you are using the designer to setup data binding. If you are just trying to show details in a UserControl, then you can do the following:
In the details UserControl, add a method to set the DataSource:
public void SetDataSource(object dataSource)
{
this.detailsBindingSource.DataSource = dataSource;
}
In the master Form, you would call this method the the "CurrentChanged" handler on the master BindingSource:
private void customersBindingSource_CurrentChanged(object sender, EventArgs e)
{
this.detailsUserControl.SetDataSource(this.customersBindingSource.Current);
}
If you need to syncronize the same list position across multiple user controls, its a bit harder.
Joe Stegman
The Windows Forms Team
Microsoft Corp.This posting is provided "AS IS" with no warranties, and confers no rights.
-
22 august 2005 05:30This is a simple soulution.
If I need a bidirectional syncronization, that is much more complicated.
Don't you have somthing like:
customersControl1.BindingSource.CurrencyManager =
customersControl2.BindingSource.CurrencyManager
If not, Can you add this feature ?
Thanks
Asaf Segal -
22 august 2005 11:31
Unfortunately we do not have that feature and you will have to write code to synchronize the BindingSource positions. I agree this would be a good feature to have. Please log this as a suggestion here:
http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=769432e5-2c72-4541-ad9f-b31dac37fc17
Thanks,
Joe Stegman
The Windows Forms Team
Microsoft Corp.This posting is provided "AS IS" with no warranties, and confers no rights.