ADO.NET 2.0 - Binding a Second Form to the Same Data Source

B

Brice

From David Sceppa's "Programming MS ADO.NET 2.0", Chapter 13, Step 9,
He is binding a second form to a Binding Source that is being passed
as a parameter. However, he is performing all Data Bindings for the
second form, manually in code. Is there an easier way?

For example, I have created a new form. From the "Data Sources" tab,
I select and drag a data source onto my form, which automatically
generates a Details View for me. This also creates a Dataset and a
BindingSource. In the EditDetail method, I set this BindingSource
equal to the one that is passed in as a parameter. However, the form
is not displaying the current record, all text boxes are empty. The
code listed below is an example of what I'm doing.

What step am I missing here?

THANKS!!

public void EditDetail(BindingSource pBindingSource) {
this.localBindingSource = pBindingSource;

if (this.ShowDialog() == DialogResult.OK)
this.localBindingSource.EndEdit();
else
this.localBindingSource.CancelEdit();
 
B

Brice

I still have an issue.

I got it working, but in order to do so, I must Clear the DataBindings
for each text box and then Add the DataBinding back.

Is there another way??

Thanks!!
 
J

Jim Rand

Assuming you are working with the Windows form designer:

1) Add the dataset to the form.
2) Add a binding source to the form. Point it at the dataset.
4) Bind all your controls to the binding source, not the dataset.
3) At run time, hot-swap the referenced dataset.

bsStatus.DataSource = Helpers.LookupTableSingleton.Instance.dsLookupTbls;

bsEnduser.DataSource = Helpers.LookupTableSingleton.Instance.dsLookupTbls;

bsOffice.DataSource = Helpers.LookupTableSingleton.Instance.dsLookupTbls;

Jim
 
B

Brice

Jim,

I am doing everything that you outline, with one exception. Instead
of hot-swapping the dataset, I am hot-swapping the binding source.
This is the desired method, because the binding source is positioned
on the current record which the user wishes to edit.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top