Question An item with the same key has already been added.

eggsandspamm

Member
Joined
May 23, 2011
Messages
10
Programming Experience
Beginner
I keep getting this error when I try to call the mainForm from another open form and change a label.text.

VB.NET:
Dim main As New mainForm

                main.Label28.Text = "TEST"
                
                Me.Hide()

Please Help :/
 
On what line is the error showing up?
 
It appears that you already have a form open named "main".
 
If you are trying to set the label of an already open form don't use "Dim main As New mainForm", just use this:

VB.NET:
mainForm.Label28.Text = "TEST"
Me.Hide()
 
That gives me "An error occurred creating the form. See Exception.InnerException for details. The error is: An item with the same key has already been added." at
VB.NET:
mainForm.Label28.Text = "TEST"
 
You shouldn't be creating a form, just setting an item of an already existing one.
 
Is the form "mainForm" shown at that point in the code?
 
After a quick Google search, it appears that this problem is computer specific. I would recommend trying the application on another computer, you can also try restarting your computer and logging in as an Administrator (or running the app as one). Sorry I couldn't be more help.
 
OK, so now you know that a new form is trying to be created, you need to find out why :). Without seeing the whole code it is kind of hard for me to help...
 
Back
Top