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
913 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET Calendar Control 5 54
Visual C# Windows Project - Clone Form 4 39
c# ftp code 3 56
Data Analysis 7 59
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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