Solved

Call Method in 1 form from another form

Posted on 2013-05-09
2
379 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
Comment Utility
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
Comment Utility
Ahh...I knew it was simple...Thanks
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

10 Experts available now in Live!

Get 1:1 Help Now