Can't open a Modal (showdialog) form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • elmbrook
    New Member
    • Feb 2010
    • 15

    Can't open a Modal (showdialog) form

    I am unable to open a child form as a modal form.

    Here is my scenario

    I have a MainForm which is a toplevel form.
    Inside the MainForm I have a Toolbar Form which is a child.
    From the Toolbar Form I call another child form.
    From that child form I need to call myModalForm.

    I have tried:

    myModalForm myform = new myModalForm ();
    myform.TopLevel = true;
    myform.MdiParen t = this.mdiparent;
    myform.ShowDial og();

    Result: 'Form that is not a top-level form cannot be displayed as a modal dialog box. Remove the form from any parent form before calling showDialog.'

    So I thought I would close the existing form first and then call the modal form

    this.close();
    myModalForm myform = new myModalForm ();
    myform.TopLevel = true;
    myform.ShowDial og();

    Result: IT works...however , it is not inside the top level form.

    So I thought I would open an instance of the MainForm and set that as the MDIParent

    this.Close(); //Close Current Form
    MainForm topform = new MainForm(); // Create new instance of MainForm
    myModalForm myform = new myModalForm ();
    topform.TopLeve l = true;
    myform.MdiParen t = topform;
    myform.ShowDial og();

    Result: 'Form that is not a top-level form cannot be displayed as a modal dialog box. Remove the form from any parent form before calling showDialog.'

    Can anyone help me get a modal form within my toplevel MainForm?

    Thanks
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    You cannot access a the parent form without closing the modal form...

    it needs to be closed first...

    although you should never use modal forms in mdi application,... . it should always be modaless...

    Modal forms should only be for dialog forms

    Comment

    • elmbrook
      New Member
      • Feb 2010
      • 15

      #3
      I think you may have mis-read the question.
      I would like to open a modal form (dialog form) within my top level form.

      They must fill out the information on my modal form first before they can continue.

      Does that make sense?

      Comment

      • elmbrook
        New Member
        • Feb 2010
        • 15

        #4
        I have found a work around but it is not pretty.

        What I have done is open the modal form from the MainForm. I have to call this method from my Child form. This works however, for every modal form in my application, I have to setup a new entry in my MainForm.

        public void Open_Modal_Form (string formname)
        {
        switch (formname)
        {

        case "myModalFor m":
        myModalForm myform = new myModalForm ();
        myform.ShowDial og(this);
        break;
        }
        }

        Comment

        Working...