-
Loading Multiple Forms
I Have a Small form (frmAddItemNumber) with a text box (txtAdditemNumber) and a command button(cmdAddItemNumber)
This is what I need the form to do.
1) Connect to the database (Complete)
2) Store the value entered into textbox to database. (Complete)
3) Load a blank form so the user can draw on it. Must be a different form for each value entered in the textbox. (Not Complete)
Any Ideas on how to do #3. Someone told me that I could use a hashtable but I could not get it to work.
Dim NewForm As New Form1
Dim MyHashTable As New Hashtable
MyHashTable.Add(1, NewForm)
Dim CurrentForm As frmAddItemNumber = MyHashTable(1)
CurrentForm.Show()
-
Your CurrentForm is a different type than the Form you put in the Hash Table. One is type Form1, the other is type frmAdditemNumber. The following code works fine:
Dim MyForm As New Form1
Dim ht As New Hashtable
Dim CurrentForm As Form1
ht.Add(1, MyForm)
CurrentForm = ht(1)
CurrentForm.Show()
And you can even leave out the CurrentForm and do:
Dim MyForm As New Form1
Dim ht As New Hashtable
ht.Add(1, MyForm)
ht(1).Show()
-
It works!! I am new at VB.Net. What is the best source of information to learn vb.net. Books, internet sites? If so, what books or sites are the best.
Thanks for your help!!!!!!!!!!!!!!!!!
-
The only thing wrong with the way my program runs right now is that I need to bring up new forms every time the add button is clicked on. Right now we have it set up to bring up form1. Is thier a way to create new forms each time?
-
You could change the type to just Form, but if I am remembering correctly you had some draw functions as part of your Form1. Why not create a new blank form that just has the draw functions you need and make that the type that you new and add to the Hashtable?
-
Well i am using my draw form instead of form1. so when the additemnumber button is seleted the draw form loads up. So now when I draw on the form I need to be able to save it to the database so I can retrieve it later. Is this posible?
-
Look into object Serialization.
-
What does this line of code mean
ht.Add(1, MyForm)
-
You are adding an object called MyForm to the hashtable collection keyed to 1.
-
I have a book that talks about serializable but ties it with xml. Saving it to a file. Do you know where I kind find info on using vb.net with an sql database?
-
I can't say that I've played around with it too much. I would guess though that you could serialize your forms into a MemoryStream, and then use a BinaryReader to read data from that stream and write it to, for example, an image field in a SQL Server database. I've never tried to do it though, so that is just a thought of a possible approach. Maybe somebody here has done it and knows better.