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
900 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
Comment Utility
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
Comment Utility
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
Comment Utility
THANKS! :D
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now