Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I need to create forms and save forms. I heard that a hashtable is a good way to do that. I have never used one before. Here is the code that I got.

THIS IS THE ERROR THAT IM GETTING

An unhandled exception of type 'System.InvalidCastException' occurred in AndersenAsi.exe

 

Additional information: Specified cast is not valid.

 

Dim CurrentForm As frmAddItemNumber = MyHashTable(1)

Dim NewForm As New Form1

Dim MyHashTable As New Hashtable

MyHashTable.Add(1, NewForm)

Dim CurrentForm As frmAddItemNumber = MyHashTable(1)

CurrentForm.Show()

Edited by JustinN
  • *Experts*
Posted

You should be able to add/retrieve a form from a hashtable. You'll need to cast it to a form when you take it out - that's the compile problem. Here's the line to change:

Dim CurrentForm As frmAddItemNumber = DirectCast(MyHashTable(1), frmAddItemNumber)

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
You should be able to add/retrieve a form from a hashtable. You'll need to cast it to a form when you take it out - that's the compile problem. Here's the line to change:

Dim CurrentForm As frmAddItemNumber = DirectCast(MyHashTable(1), frmAddItemNumber)

 

-ner

 

 

Tried what you posted but the result was the same.

 

Dim NewForm As New Form1

Dim MyHashTable As New Hashtable

MyHashTable.Add(1, NewForm)

Dim CurrentForm As frmAddItemNumber = DirectCast(MyHashTable(1), frmAddItemNumber)

CurrentForm.Show()

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...