Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Call Method in 1 form from another form

Posted on 2013-05-09
2
Medium Priority
?
389 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
[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 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

660 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