Solved

Sharing A Data context between Usercontrols

Posted on 2011-03-15
9
298 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
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.

 
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

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

28 Experts available now in Live!

Get 1:1 Help Now