In Form2
, you have code that creates a new Form1
instance and does something to it. How can that help you affect the Form1
instance that already exists? If you had a notepad and I went and bought a new notepad of the same type and wrote on it, would you expect what I wrote to magically appear in your notepad? Of course not, so why should that happen with forms? The proper way to do this is for Form2
to simply expose the data and then for Form1
to retrieve it.
I don't know what's in the tutorial recommended above but you might also follow the Blog link in my signature below and check out my posts on Data Among Multiple Forms. You can skip the first part because that is specific to VB. Part 2 is the quick and dirty way and part 3 is the right way.
If you want to close the second form when the data is available then you should almost certainly be calling ShowDialog
rather than Show
. In that case, you can simply retrieve the data when the method returns. If Show
is the right option because you want the second form to remain open then the second form should raise an event that the first form can handle in order to know when to retrieve the data. In fact, the data can even be provided by the event if you like. There's a post on Custom Events in my blog too.