| I have two forms within a c# winform app, one form contains a datagridview
| bound to a binding source, the other form contains a detailed view of that
[quoted text clipped - 9 lines]
| CustomersBindingSource = oBindingSource;
| }
Why not put one BindingSource on each form and connect their DAtaSource
properties to the same underlying list or dataset ?
Joanna

Signature
Joanna Carter [TeamB]
Consultant Software Engineer
Rob Dob - 21 Sep 2006 21:54 GMT
> Why not put one BindingSource on each form and connect their DAtaSource
> properties to the same underlying list or dataset ?
you mean like this? ( I tried that and it seems to work okay, until I
select a record from the first form after sorting by column and then it
grabs the wrong record )
public frmCustomersDetail( DataSetOrders oDataSet)
{
InitializeComponent();
this.dataSetOrders = (DataSetOrders)oDataSet;
CustomersBindingSource.DataSource = (DataSetOrders)oDataSet;
CustomersBindingSource.Position = oBindingSource.Position;
}
Hi,
> Hi,
>
[quoted text clipped - 11 lines]
> CustomersBindingSource = oBindingSource;
> }
You have to make a difference between an instance and a variable.
You have put a BindingSource on the Form which you have bound. So inside
InitializeComponent() an instance of BindingSource is created, it's assigned
to CustomersBindingSource and it's bound to various Controls.
Then you change the variable CustomersBindingSource to oBindingSource but
the Control's aren't bound to a _variable_ but to an _instance_ (set inside
InitializeComponent()). So they remain bound to the same instance.
So it's definitely not a bug, just the normal way instances and variables
work. But you could say it's a limitation of the designer (databinding) in
that it can't refer to instances on other Forms. (in code this isn't a
problem)
HTH,
greetings
Rob Dob - 22 Sep 2006 12:31 GMT
Hi,
I understand what your saying, but to have to manually rebind controls in
order to be able to pass the Bindingosurce is CRAZY, can't you assign just
the address. to that instamce as you would in c++ or does c# not support
this.. I sure can't see myself retyping all those databindings..
Thanks,
>> public frmCustomersDetail(BindingSource oBindingSource)
>> {
[quoted text clipped - 19 lines]
> HTH,
> greetings
Rob Dob - 22 Sep 2006 12:39 GMT
Why couldn't CustomersBindingSource be *CustomersBindingSource and then we
could just assign the address of oBindingSource as in
*CustomersBindingSource = &oBindingSource;
thanks,
> Hi,
>
[quoted text clipped - 32 lines]
> HTH,
> greetings
Bart Mermuys - 22 Sep 2006 17:06 GMT
Hi,
> Why couldn't CustomersBindingSource be *CustomersBindingSource and then
> we could just assign the address of oBindingSource as in
> *CustomersBindingSource = &oBindingSource;
Consider ( C# ) :
BindingSource A = new BindingSource();
// A is a reference to the new BindingSource
BindingSource B = A;
// B is now too a reference to that BindingSource (as in Binding storing the
datasource in it's own variable)
A = new BindingSource();
// A is now a reference to another BindingSource, but B didn't change
Since BindingSource is a reference type, this would be "similar" to the
following in C++ :
BindingSource* A = new BindingSource();
BindingSource* B = A;
A = new BindingSource(); // B didn't change
Though something like this is possible in C++:
BindingSource* A = new BindingSource();
BindingSource** B = &A;
A = new BindingSource(); // *B also changed
But that's C++ not C# and if A would be a member variable instead of a local
one then it would be more complicated (see c++ pointer-to-member) so i don't
believe this would solve this problem.
The problem is you can't change InitializedComponent where the BindingSource
is created and bound, it doesn't need to create one(at runtime), you already
have one.
So i'm still considering this a designer shortcoming and currently have no
solution other than (re)binding in code... you could automate this, by
looping through all controls and databindings, removing bindings and adding
new ones with a different DataSource, pretty ugly too.
HTH,
Greetings
> thanks,
>
[quoted text clipped - 35 lines]
>> HTH,
>> greetings