Solved

Sharing A Data context between Usercontrols

Posted on 2011-03-15
9
304 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

636 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