MDIParent property

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
I'm opening a mdichild (Form2) within another mdichild (Form1). In Form1 I
have:
Form2.MdiParent = Me.MdiParent 'No problem here
....
....
If Form2.ShowDialog = DialogResult.OK Then 'I get an error message here.
This is the error: Forms that are not top level forms cannot be displayed as
modal dialog. Remove the form from any parent form before calling ShowDialog.
When I remove:
Form2.MdiParent = Me.MdiParent
Then I don't get error message but the MDIParent value for Form2 is nothing.
I need to assign mdiparent to the form2 and at the same time use ShowDialog.
Does anyone have any suggestions?
Thanks in advance,
Roy
 
Roy said:
I need to assign mdiparent to the form2 and at the same time
use ShowDialog. Does anyone have any suggestions?

MDI child forms cannot be displayed as Dialog forms, hence the error you are
getting.

One way you could fix this is to add a public property to Form2, which
allows you to set the MDI form, like this:

\\\
Public MyMainMDIForm As Form
///

....then in your code in Form1, instead of setting the MdiParent, set the
MyMainMDIForm property instead. This will stop VB from thinking your form
should be an MDI child, and will allow ShowDialog() to work. When Form2
needs access to the MDI form, it can access it through the MyMainMDIForm
reference instead of through the MdiParent property.

Hope that helps,
 
Back
Top