Access Dictionary from child User Control

Mandragoran

New member
Joined
Dec 15, 2016
Messages
4
Programming Experience
1-3
I have a Dictionary that is defined in the main form. I need to access that Dictionary from the class that defines a usercontrol that is located in a class library. The user controls are not on the main from at load time and are only added later. is there a way I can access the Dictionary like this or do I need to find another way.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,283
Location
Sydney, Australia
Programming Experience
10+
The form would have to pass the Dictionary into the user control when it creates it, either as an argument to the constructor or another method or by setting a property. That's how you always get any data into any object.
 

Mandragoran

New member
Joined
Dec 15, 2016
Messages
4
Programming Experience
1-3
First of all apologies I'm a newbie at this. The main problem I'm running into is that I keep getting an error when I try to run the program or add the usercontrol to the main form. "An item with the same key has already been added." from what I've been able to find out this is because I have two dictionary items in the program that have the same set of key:values.

I tried adding the dictionary object by making it a parameter to the new sub when the usercontrol is created, like so;

Public Sub S_M_Chocolate()
Call CleanHouseProtocol()
Dim thetemplate As New CMethodChocolate(Lightweaver)
thetemplate.Name = "thetemplate"
thetemplate.Location = New Drawing.Point(0, 0)
MasterGroupbox.Controls.Add(thetemplate)
End Sub

But i'm still getting the same "Item with the same key..." error.

Did I completely misunderstand your answer or am I doing it wrong?
 
Top Bottom