Check if child form is open does not work

Hi
I have a method in my MDI parent form witch checks if a child form is already open:

public bool KidsOpen(Form FormName)
        {
            Form[] childform = this.MainDockingManager.MdiChildren;
            if (this.MainDockingManager.MdiChildren.Length == 0)
            {
                return false;
            }
            else
            {
                foreach (Form Myform in childform)
                {
                    if (Myform.Name == FormName.Name)
                    {
                        Myform.BringToFront();
                        return true;
                    }
                }
                return false;
            }
        }

this works when i open a child form from menu in the parent with this method..

case "Edit user":
                        {
                            EditUser form = new EditUser();
                            form.Text = "Edit user ";
                            form.MdiParent = this;
                            if (!KidsOpen(form))
                            {
                                form.Show();
                            }
                            else
                            {
                                SetActiveForm(form);
                            }
                            break;
                        }
Now, I want to open a child form from another child form..there i user following method..

private void EditUserFromGrid(string username)
        {
            MainAdmin main = new MainAdmin();
            Form mdiForm = this.ParentForm;
            if (mdiForm.ActiveMdiChild != null)
            {
                if (username != null)
                {
                    EditUser form = new EditUser(username);
                    form.Text = "Edit user";
                    form.MdiParent = mdiForm;
                    if (!main.KidsOpen(form))
                    {
                        form.Show();
                    }
                }
            }
        }

this opens the form inside the parent but does not find the already open children...
The MdiChildren is null and Length is also null

  Form[] childform = this.MainDockingManager.MdiChildren;
            if (this.MainDockingManager.MdiChildren.Length == 0)
but it works when i call the method from the MDI parent.

Regards
ize_manAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RimvisCommented:
if (!main.KidsOpen(form))

shouldn't it be

if (!mdiForm.KidsOpen(form))
0
ize_manAuthor Commented:
I tried that but it did not work... :-( so I had to add this to my method to be able to access KidsOpen method

MainAdmin main = new MainAdmin();

this one does find the parent form for the child i am calling from

Form mdiForm = this.ParentForm;

this was my first approach...it looked obvious to me...but it doe's not work. (I wonder why!!) even if it seems like the mdiForm and main has exactly same values I am not able to get KidsOpen method by using mdiForm...
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Instead of:

    Form mdiForm = this.ParentForm;

Try:

    yourMdiParentTypeHere mdiForm = (yourMdiParentTypeHere)this.MdiParent;

Then as Rimvis said...

Change:

    if (!main.KidsOpen(form))

To:

    if (!mdiForm.KidsOpen(form))

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ize_manAuthor Commented:
This does not work

yourMdiParentTypeHere = MainAdmin (That's what you mean??)

MainAdmin main = (MainAdmin)this.MdiParent;

main is null in debug mode....so I tried this..

MainAdmin main2 = (MainAdmin)this.ParentForm;

then i run the rest..

if(!main2.KidsOpen(form))
{
....

and it worked :-) ..so I believe that problem is solved...
Thanks for the help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.