calling the method of a base class by reflection

G

Guest

Some weeks ago, I needed to access the method "get_DataGridRows" from the System.Windows.Forms.DataGrid class.
I successfully worked it out with the following call:

MethodInfo mi = DataGridInstance.GetType().GetMethod("get_DataGridRows", BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);

I've now created a class called "MyDataGrid" that inherits from the System.Windows.Forms.DataGrid class.
My problem is that the previous code does not work any more for MyDataGrid instances: it always returns an <undefined value>.

I suppose that's because I am trying to access a method that is not available in the inherited class. So I tryed with this call: base.GetType().GetMethod().... inside the inherited class, but I got an <undefined value> again.

Any ideas?
TIA

m|3
 
C

Claes Bergefall

Try using this.GetType().BaseType.GetMethod()...

/claes


mark13 said:
Some weeks ago, I needed to access the method "get_DataGridRows" from the
System.Windows.Forms.DataGrid class.
I successfully worked it out with the following call:

MethodInfo mi = DataGridInstance.GetType().GetMethod("get_DataGridRows",
BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase |
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Static);
I've now created a class called "MyDataGrid" that inherits from the
System.Windows.Forms.DataGrid class.
My problem is that the previous code does not work any more for MyDataGrid
instances: it always returns an said:
I suppose that's because I am trying to access a method that is not
available in the inherited class. So I tryed with this call:
base.GetType().GetMethod().... inside the inherited class, but I got an
 
G

Guest

Claes,

thank you very much for your reply. I finally had a chance to try it and it
worked!

Mirco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top