How Do I Pass Bindingsource to Another Winform.

  • Thread starter Thread starter Rob Dob
  • Start date Start date
R

Rob Dob

Hi,

I have two c# Winforms. the first form has a datagridview who's datasource
is a
bindingsource. when you double click on a datagridview row it then opens my
second form, which has some databound controls, text boxes that are bound to
another bindingsource. Both bindingsources are bound to the same dataset,
and contain the same information. Within my second forms Load method I fill
my dataset that is bound to my bindingsource with the content of the current
record selected from my first form. but the problem is that when I save the
changes made within my second form and close it that these changes are not
reflected within my first forms datagridviews contents unless I Fill the
dataset again.

I'm assuming that what I need to do is use the bindingsource that is
contained within my first form in my second form, that way any changes will
be immediately reflected back into my main form.. If this is the case, how
do I go about doing this.?

Any suggestions would be greatly appreciated.

Thanks
 
I first would like to say that I am a novice and I'm just throwing it
out there, but my belief is that you would have to pass a reference to
that binding source in your call to Load the second Form, that way any
changes made are being done to the first winform's binding source.
I'd actually like to know how to do this myself if this isn't the
best(or even close to right) way of getting the information to sync.
 
Hi,

Thats what I thought, but how do you assign the value of the bindsource
from winform1 to the new bindingsource on the winform2 side. In C++ I would
know how to do this but in c# I don't have a clue as it doesn't seem to make
use of pointers... and not sure how you would pass something by reference,
i.e @bindingsource

Any help would be appreciated...
 
sorry for the long pause b/w posts....

it would be along the lines of
Form form2 = new Form(ref BindingSource);

and then in form2's constructor it'd look like:

public form2(ref BindingSourceName)
{
..
..
enter code to manipulate BindingSourceName
..
..
}

you can set it to that other BindingSource in form2, for something
along the lines of

public form2(ref BindingSourceName)
{
..
BindingSource2 = BindingSourceName;
enter code to manipulate BindingSource2
..
..
}

and then your changes should be reflected, once again, I'm actually
playing with that kind of code myself, and I don't have the means right
now to test and see if that is even possible to pass a whole
bindingsource to another form
 
Rob Dob said:
I have two c# Winforms. the first form has a datagridview who's datasource
is a
bindingsource. when you double click on a datagridview row it then opens my
second form, which has some databound controls, text boxes that are bound to
another bindingsource. Both bindingsources are bound to the same dataset,
and contain the same information. Within my second forms Load method I fill
my dataset that is bound to my bindingsource with the content of the current
record selected from my first form. but the problem is that when I save the
changes made within my second form and close it that these changes are not
reflected within my first forms datagridviews contents unless I Fill the
dataset again.

I'm assuming that what I need to do is use the bindingsource that is
contained within my first form in my second form, that way any changes will
be immediately reflected back into my main form.. If this is the case, how
do I go about doing this.?

Any suggestions would be greatly appreciated.

Thanks

I am dealing with a similar issue. My suggestion is take a look at the
BindingSource.ResetBindings method at
http://msdn2.microsoft.com/en-us/library/system.windows.forms.bindingsource.resetbindings.aspx

Please post your ongoing experiences on this. I am sure between us we can
work something out.

Mark
 
Back
Top