PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Does one know how to bind a BindingDataSource with designer ?

Reply

Does one know how to bind a BindingDataSource with designer ?

 
Thread Tools Rate Thread
Old 10-04-2006, 12:59 PM   #1
olrt
Guest
 
Posts: n/a
Default Does one know how to bind a BindingDataSource with designer ?


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 !

  Reply With Quote
Old 11-04-2006, 09:42 AM   #2
=?Utf-8?B?Z3V5YmFy?=
Guest
 
Posts: n/a
Default RE: Does one know how to bind a BindingDataSource with designer ?

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.
--
GuyBar


"olrt" wrote:

> 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 !
>
>

  Reply With Quote
Old 12-04-2006, 04:29 PM   #3
olrt
Guest
 
Posts: n/a
Default Re: Does one know how to bind a BindingDataSource with designer ?

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).
}
------------------------------------------------------------

  Reply With Quote
Old 14-04-2006, 11:59 AM   #4
=?Utf-8?B?Z3V5YmFy?=
Guest
 
Posts: n/a
Default Re: Does one know how to bind a BindingDataSource with designer ?

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.
--
GuyBar


"olrt" wrote:

> 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).
> }
> ------------------------------------------------------------
>
>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off