Solved

Sharing A Data context between Usercontrols

Posted on 2011-03-15
9
299 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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