Link to home
Start Free TrialLog in
Avatar of Kevin Robinson
Kevin Robinson

asked on

Sharing A Data context between Usercontrols

I have a Organisation Details form with different user controls.   One for Organisation Details one for Addresses.  I am using the entity framework and have a relationship between the three you would expect.    

So How do I go about linking these up.  

1) Do I create a data context for the main form and pass this to each of the user controls?
2) I pass in a reference to to the Organisation to the Address user control?
3) Anything else?
Avatar of David L. Hansen
David L. Hansen
Flag of United States of America image

There are several ways to allow objects to access another object.  What exact object do you wish other objects to use?
Avatar of Kevin Robinson
Kevin Robinson

ASKER

I would like to be able to add an address in the address user control (working in isolation).  This will add an an address to the base organisation.
I'm guess you have a listbox or some kind of grid that allows the user to add data to it (in this case addresses) correct?  And you want another control on the same form (containing organization data) to be aware of the new address correct?

I have a user control with organisation details  Org name etc.  I have another user control with a list of addresses for that organisation.  

I have a button on my parent form "Add Address" which opens an "Add Address" Window to allow the user to add a new address.  

Of course it would be nice then once I added this to updated the address list with the new address.
ASKER CERTIFIED SOLUTION
Avatar of David L. Hansen
David L. Hansen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My question though is how to I manage to add and saving the address.  i am using entity framework.

When a new address is entered are you saving it to the database?
Yes
Sorry for being out so long.  I would just refresh your form from the database just like you do when it is first opened.  That will always pull the latest changes as they happen.