Using VS 2005 Release Candidate, C#
SITUATION:
I have 2 forms, form1 is showing a datagridview, form2 is showing the selected record in de datagridview of form1 using textboxes and others.
I'm using a bindingsource bs1 (form1) en bs2 (form2). In form1 I double-click on the datagridview and show form2 (I'm sending the BindingSource bs1 as a parameter) using the following method:
- form2 f2 = new form2();
- f2.LoadDS(BindingSource bs1);
- f2.Show();
In form2 LoadDS contains...
void LoadDS(BindingSource bs);
{
- bs2.DataSource = bs.DataSource;
- bs2.DataMember = bs.DataMember;
- bs2.Position = bs.Position;
}
And it works.
PROBLEM:
But I want that the navigationbuttons on form1 & form2 do the same thing, meaning changing the position of databinding in form1 and form2 and therefore I add this line:
- bs2 = bs ;
But only the navigation buttons of form2 react and change the position in the DataGridView of form1. Nothing happens on form2.
QUESTION:
What am I doing wrong
Thx.

How can I use 1 databinding for 2 (or more) forms
Jim King 2000
That's what I have done. It doensn't work properly (as described).
Am I doing something wrong or is it a VS 2005 RC bug
Thx again.
IssamElbaytam
You are very close. Keep a reference to the parent form binding source and change your current bindingsource position when the parent one changes. I just did an app the hard way as you described with all the rebinding. This is much cleaner.
BindingSource parentSource;public void LoadDS(BindingSource bs)
{
parentSource = bs;
parentSource.CurrentChanged += new EventHandler(parentSource_CurrentChanged);
bs2.DataSource = parentSource; }
void parentSource_CurrentChanged(object sender, EventArgs e)
{
bs2.Position = parentSource.Position;
}
LoyolaStalin
So, your code would look like this:
void LoadDS(BindingSource bs);
{
}
Hope this helps.
Daniel.
This posting is provided "as-is".
manguyus
Your application is using a different binding source in Form2: it is using bs2. Form2 should be using the same BindingSource as Form1 uses.
Here is a sample code. Form1 contains a data grid view, Form2 contains two text boxes bound to the same BindingSource as the data grid view. Changing position in the data grid view in Form1 will refresh the text in the text boxes in Form2.
Form1:
private void Form1_Load(object sender, EventArgs e)
{
DataTable tbl = new DataTable();
tbl.Columns.Add("Name");
tbl.Columns.Add("Points", typeof(int));
tbl.Rows.Add("Adrian", 10);
tbl.Rows.Add("John", 8);
tbl.Rows.Add("Naomi", 12);
BindingSource bs = new BindingSource();
bs.DataSource = tbl;
this.dataGridView1.DataSource = bs;
Form2 f = new Form2(bs);
f.Show();
}
Form2:
public Form2(BindingSource bs)
{
InitializeComponent();
this.bs = bs;
// Bind the two text boxes.
this.textBox1.DataBindings.Add("Text", bs, "Name"); this.textBox2.DataBindings.Add("Text", bs, "Points");}
chrisOmni
Is this a known boug, I am having the same difficulty, has anyone come up with a resolution
thanks,
ks10
I understand.
Apparently I have to REDO the Databinding. I'm supprised that this is necessary because I already have a binding with these fields but then off course with the standard bindingsource of this form2.
I thought that with the command this.bs = bs (which is by reference) also all other things are (re)linked to this new bindingsource. That's why I also tried the bs.ResetBinding() but that doesn't work either.
Tested it as you described and it works fine! Thx you.
Gautam25470
But then again... explain this...
I have a base form with a DataBinding basicdb and I create navigationbuttons for basicdb.
I create a new form inhertid from the base form.
I drop in desing-mode a table "Address" to the the form. Automatically a bindingsource, dataadapter,... is created. The bindingsource is normaly called addressBindingSource.
In the Load-method I do this:
basicdb = addressBindingSource;
I run and my (inherited) navigation buttons do work and the data (datagridview or textboxes that ARE binded with addressBindingSource) display the correct data anytime without REBINDING to basicdb.
Do you have an explanation
Thank you.