This isn't necessarily the best option available (see kenobewan''s post) but it is possible.
Two things need to happen for this to work properly;
- You need to declare your DataSet as Public
- You need to pass a reference of the instance of form1 to the second form to use it though.
The second part is a bit complicated. You need to modify Form2's constructor. If you don't know what that is, read
this. The constructor is the Sub New() that your program may or may not contain.
You need to add a global variable to the form like this:
and you need your constructor to take a parameter, like this:
- Public Sub New(f1 as Form1)
-
f1Ref = f1
-
End Sub
Now, when you want to show Form2, you need to do it like this
Note that this is the correct way. Just saying Form2.Show() is wrong. - Dim f2 as New Form2(me)
-
f2.Show()
now you can get to Form1's DataSet like this (I'm assuming you called it DataSet1, so just replace that with whatever you need)
- Dim ds as DataSet
-
ds = f1Ref.DataSet1