method.invoke question

Stephen Prestwich 21 Reputation points

I have a master form with a bunch of sub forms. Each sub form has the same method name "RefreshData". I need help finishing the invoke method to execute the refreshdata method on the subform from the master form. My code is below.

button click event on master form. ClsCommon.NewRfrmCurr holds the current sub form object.

var type = ClsCommon.NewRfrmCurr.GetType();

                    MethodInfo[] methods = type.GetMethods();
                    foreach (MethodInfo method in methods)
                        if (method.Name == "RefreshData")
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,528 questions
0 comments No comments
{count} votes

Accepted answer
  1. P a u l 10,411 Reputation points

    It should just be:

    method.Invoke(ClsCommon.NewRfrmCurr, new object[] {  })

    Does RefreshData accept arguments? If so you'll need to add them into that object array:

    method.Invoke(ClsCommon.NewRfrmCurr, new object[] { arg1, arg2, arg3 })

0 additional answers

Sort by: Most helpful