Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

Sharing A Data context between Usercontrols

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
Kevin Robinson
Asked:
Kevin Robinson
  • 5
  • 4
1 Solution
 
David L. HansenProgrammer AnalystCommented:
There are several ways to allow objects to access another object.  What exact object do you wish other objects to use?
0
 
Kevin RobinsonPrivate VB.NET ContractorAuthor Commented:
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
 
David L. HansenProgrammer AnalystCommented:
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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
Kevin RobinsonPrivate VB.NET ContractorAuthor Commented:

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
 
David L. HansenProgrammer AnalystCommented:
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
 
Kevin RobinsonPrivate VB.NET ContractorAuthor Commented:
My question though is how to I manage to add and saving the address.  i am using entity framework.

0
 
David L. HansenProgrammer AnalystCommented:
When a new address is entered are you saving it to the database?
0
 
Kevin RobinsonPrivate VB.NET ContractorAuthor Commented:
Yes
0
 
David L. HansenProgrammer AnalystCommented:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now