Why doesn\'t the following work?
Two forms; first calls the second. Second form has a DataGridView on it - it has no columns in it, they\'re added by the program, along
I think you have a convergence of several things causing this. First, forms are classes and ought to be instanced explicitly. Instead of Form2.ShowDialog()
do this:
Using frm As New Form2 ' create instance
frm.ShowDialog
' do something
End Using ' dialogs are also a resource
Using
/ .Dispose
is not needed with normal forms because when you Close them, they are disposed of. Not so with dialogs since we unusually just Hide them so we can get info from them.
Next, the Form_Load event is only called the FIRST time you show the form. See MSDN: Occurs before a form is displayed for the first time.
So by reusing a non disposed-of Form2
, the Load event isnt called and the code in the Load event isnt executed. It should work fine if you dispose of and create new form instances. BTW this applies to all forms, not just dialogs.