Results 1 to 3 of 3

Thread: Access Dictionary from child User Control

  1. #1
    Mandragoran is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2016
    Posts
    4
    Reputation
    0

    Access Dictionary from child User Control

    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.

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,802
    Reputation
    1705
    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.

  3. #3
    Mandragoran is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2016
    Posts
    4
    Reputation
    0
    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?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •