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?
LVL 3
Kevin RobinsonPrivate VB.NET ContractorAsked:
Who is Participating?
 
David L. HansenConnect With a Mentor Programmer AnalystCommented:
Are you storing this information in a database?  I assume you are.  When the user commits the new address to the database, just have the form refresh (executing the select statement) and repopulating the controls.  If you keep track of the current organization highlighted then you just need to move the focus to that organization and the newly added address should be included in the address list control.
0
 
David L. HansenProgrammer AnalystCommented:
There are several ways to allow objects to access another object.  What exact object do you wish other objects to use?
0
 
Kevin RobinsonPrivate VB.NET ContractorAuthor Commented:
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.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
David L. HansenProgrammer AnalystCommented:
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?
0
 
Kevin RobinsonPrivate VB.NET ContractorAuthor Commented:

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.
0
 
Kevin RobinsonPrivate VB.NET ContractorAuthor Commented:
My question though is how to I manage to add and saving the address.  i am using entity framework.

0
 
David L. HansenProgrammer AnalystCommented:
When a new address is entered are you saving it to the database?
0
 
Kevin RobinsonPrivate VB.NET ContractorAuthor Commented:
Yes
0
 
David L. HansenProgrammer AnalystCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.