Link to home
Start Free TrialLog in
Avatar of ize_man
ize_manFlag for Sweden

asked on

Open childform in mdi parent from another childform..

Hi

I have a MDI paren form witch works fine... now I want to open a existing childform when i double click on a row in a DataGrid... Followin code opens the form, but outside the "parent"

 EditUser form = new EditUser(username);
form.Show();

and when i run this code the form does not appear at all....

Form mdiForm = this.ParentForm;

if(mdiForm.ActiveMdiChild != null)
{
if(username != null)
{
EditUser form = new EditUser(username);
form.TopLevel = false;
form.Parent = mdiForm;
form.Show();
}
}

I have a Telerik DockingManager on my MDI Parent witch displays the child forms in a different "Tab"...

Any idea?

Regards
Avatar of ize_man
ize_man
Flag of Sweden image

ASKER

Forgot a small issue...
When i run debug mode the EditUser form i am trying to open hat IsMdiChid propery set to null....maybe that's the proplem. If so, how do I fix that?
Shouldn't you set the MdiParent? Like:

form.MdiParent = mdiForm.MdiParent;
ASKER CERTIFIED SOLUTION
Avatar of MortenSlotKristensen
MortenSlotKristensen
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Damn it.. Just the first thing I posted :p
Avatar of ize_man

ASKER

hahah....that's just the case..

I just figured it out. You soulution was the right track but i had to "set" the MdiParent before calling the EditUser form.. followin code snippet does the trick.

Form mdiForm = this.ParentForm; //THIS IS NECESSARY
            if (mdiForm.ActiveMdiChild != null)
            {
                if (username != null)
                {
                    EditUser form = new EditUser(username);
                    form.MdiParent = mdiForm;
                    form.Show();
                }
            }
Yes indeed! :) That should do it.
Avatar of Nasir Razzaq
You are not setting the MDIParent property so IsMDIChild property is null or false. You can use a public variable in EditUser form and set that to the parent form like this.

Public Class EditUser
          Inherits Form
public fmain as frmMain
...
dim f as new frmNewUser
f.MDIParent=fmain
f.Show
End Class

Sorry i had this window open for sometime and then pasted the comment and other solution was already posted. Please ignore.