Solved

Call Method in 1 form from another form

Posted on 2013-05-09
2
381 Views
Last Modified: 2013-05-09
I thought this would be relatively simple but I am stuck at the moment. Any help would be appreciated.

I have a form with a grid in it. If I double click an item in the grid I would like to:

1. Check if the form is already open
2. If open  then it should call a method(Get_Sub_To_Edit) on that form
3. If closed it should open the form(subDataEntry) and call a method(Get_Sub_To_Edit) on that form.

My form subDataEntry may or may not be opened by my form so I cannot pass across this form to the subDataEntry form.

    private void grdSubs_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {

            int row = grdExceptions.CurrentRow.Index;
            int id = Convert.ToInt32(grdSubs["subid", row].Value.ToString().Trim());

            bool formisopen = false;

            foreach (Form OpenForm in Application.OpenForms)
            {
                if (OpenForm.GetType() == typeof(subDataEntry))
                {

                    OpenForm.Select();
                    OpenForm.Get_Sub_To_Edit(id); // Does not work. Method is unavailable
                    formisopen = true;
                }
            }

            if (formisopen == false)
            {
                subDataEntry myform = new subDataEntry();
                myform.MdiParent = this.MdiParent;
                myform.Get_Sub_To_Edit(id);
                myform.Show();

            }


        }

Open in new window

0
Comment
Question by:elmbrook
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39153991
You need to CAST the form to the correct type.

Change:

    OpenForm.Get_Sub_To_Edit(id);

To:

    ((subDataEntry)OpenForm).Get_Sub_To_Edit(id);
0
 

Author Closing Comment

by:elmbrook
ID: 39154026
Ahh...I knew it was simple...Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Events in static methods 3 50
Excel file not created as expected 7 48
Anyway to make "All" the default in the dropdown? 6 34
C#.NET and microsoft certification. 3 30
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

15 Experts available now in Live!

Get 1:1 Help Now