Solved

Call Method in 1 form from another form

Posted on 2013-05-09
2
383 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 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