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
918 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

622 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