PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Does one know how to bind a BindingDataSource with designer ?
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Does one know how to bind a BindingDataSource with designer ?
![]() |
Does one know how to bind a BindingDataSource with designer ? |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 ! |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 ! > > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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). } ------------------------------------------------------------ |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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). > } > ------------------------------------------------------------ > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

