Solved

Sharing A Data context between Usercontrols

Posted on 2011-03-15
9
303 Views
Last Modified: 2012-08-14
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?
0
Comment
Question by:Kevin Robinson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 35138848
There are several ways to allow objects to access another object.  What exact object do you wish other objects to use?
0
 
LVL 3

Author Comment

by:Kevin Robinson
ID: 35138902
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
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 35139068
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:Kevin Robinson
ID: 35139167

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
 
LVL 15

Accepted Solution

by:
David L. Hansen earned 500 total points
ID: 35139230
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
 
LVL 3

Author Comment

by:Kevin Robinson
ID: 35139260
My question though is how to I manage to add and saving the address.  i am using entity framework.

0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 35139525
When a new address is entered are you saving it to the database?
0
 
LVL 3

Author Comment

by:Kevin Robinson
ID: 35176151
Yes
0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 35185033
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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question