Solved

c# check if mdi form is open and then active it if it is, partial code returning errors

Posted on 2011-03-16
3
912 Views
Last Modified: 2013-12-17
hi all,

im trying to check if a form is open on click and if it is go to that tab instead of creating a new one
my code is below and it returns this error on click

"Collection was modified; enumeration operation may not execute."
private void iHome_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FormCollection fc = Application.OpenForms;

            foreach (Form frm in fc)
            {
                if (frm.Name == "frmHome")
                {
                    frm.Activate();
                    return;
                }

                Athena.frmHome Home = new Athena.frmHome();
                Home.MdiParent = this;
                Home.Show();
            }

        }

Open in new window

0
Comment
Question by:awilderbeast
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 35147359
private void iHome_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FormCollection fc = Application.OpenForms;

            foreach (Form frm in fc)
            {
                if (frm.Name == "frmHome")
                {
                    frm.Activate();
                    return;
                }
            }      ///   ***************  Note this was after the next 3 statements before

                Athena.frmHome Home = new Athena.frmHome();
                Home.MdiParent = this;
                Home.Show();
        }
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 35147368
Your original code only checked the first form then added a new form is the first didn't meet your requirements.  I assume this was not what you wanted.
0
 
LVL 1

Author Closing Comment

by:awilderbeast
ID: 35147375
THANKS! :D
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question