Solved

Call Method in 1 form from another form

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

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

636 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