Does one know how to bind a BindingDataSource with designer ?

O

olrt

Hello,

Here's the case I want to address with the help of the designers (I'm
using Visual Studio C# Express).
Let's say I designed a typed DataSet (named BidonDataSet).
Let's say I designed a Windows Form (named Form1).
In this form I designed a DataGridView (named DgArticles).
I bound DgArticles to the generated aRTICLESBindingSource itself bound
to the datamember "ARTICLES" of BidonDataSet instance in my form.

Now I designed a second Windows Form (named Form2).
In this form I designed a TextBox.
I want the TextBox to be bound to the "ID" column of
aRTICLESBindingSource.

I managed to bind manually the TextBox with code like this :

------------------------------------------------------------
this.iDTextBox.DataBindings.Add(new
System.Windows.Forms.Binding("Text", src, "ID", true));
where src is aRTICLESBindingSource.
------------------------------------------------------------

It works great !!

Now the question :
Could it be possible to have the designer bind a TextBox to a
BindingSource defined in an another Form ? All I can see is that the
Wizard only proposes me a list of DataSets and DataMembers...

Thanks for your help !
 
G

Guest

since the bindingsource machanizm of the .net is creating cutom non static
classes that are used in the binding process, both classes will have a
different instance of the binding source class, which means you cannot bind
to a datasource found on another form. However you can use the
CurrencyManager's position property of the second form to point the second
binding source to the row selected on the grid of the first form. You can
find an example on how to do that on the MSDN.
 
O

olrt

I don't agree with you.
You CAN bind a control to a binding source of another form.
I managed so, here's the code :

------------------------------------------------------------
void BindControls(BindingSource src)
{
this.iDTextBox.DataBindings.Add(new
System.Windows.Forms.Binding("Text", src, "ID", true));
// where src is aRTICLESBindingSource (member of the other Form).
}
------------------------------------------------------------
 
G

Guest

Yes you are right. You could also just pass the DataSource from one file to
another. But the position of the Datasource will not be passed. That means
that if you selected the Third row in the gtid of the first form, the second
form will present the firat row in the DataSource. To enable the second form
to select the same raw that was selected in the first form you need to use
the CurrencyManager and to copy the position from the first form to the
second form.
 

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