Solved

Sharing A Data context between Usercontrols

Posted on 2011-03-15
9
297 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now