DataGrid Question

I was recently using reflection to access method get_DataGridRows from a System DataGrid like this:

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

      System.Array dgra = (System.Array)mi.Invoke(dg1,null);

Now I have created a custom datagrid control that inherits from System DataGrid.  Now every time I try to execute the previous code, I get a null reference error.  The problem is that I cannot get a MethodInfo object from a type of my custom datagrid.  How would I accomplish this with my own custom datagrid?????

Thanks,
Kendal
gvector1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
This seems like a lot of unnecessary magic.  Are you trying got access to something that you normally don't have access to?  Was there a reason for this code?

Bob
0
gvector1Author Commented:
It comes from someone elses code I am trying to clean up.  The datagrid was included within a form and heavily modified.  He then copied the same code into other forms.  I am trying to clean the code up and contain it within a custom datagrid control.  I have already included the code that will allow the datagrid to be double clicked if the readonly type is true and to have rowselect.  One of the things is that he sizes the datagrids row heights to a certain size when it is draw because he draws icons within some cells that causes the datagrids row heights to increase, so therefore he is trying to size the row heights down to a fixed size.
0
Bob LearnedCommented:
So, when does this code get called?

Bob
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

gvector1Author Commented:
Pretty much anytime the datagrid is redrawn.
0
Bob LearnedCommented:
What is dg1 (variable instance)?  Where is dgra used?

Bob
0
gvector1Author Commented:
dg1 is a custom control that I wrote that inherits from System Datagid.
dgra is ends up being an array of datarows that are contained within the datagrid.  It is later looped through in order to determin and set the datarow height.
0
Bob LearnedCommented:
I am not sure that I can figure out a solution for you, given what I know about your system, and the framework, and because I work with purchased data grid control (ComponentOne FlexGrid).

Bob
0
gvector1Author Commented:
Maybe this will help:
This code was aquired through the syncfusion website's Q&A : http://64.78.52.104/FAQ/WinForms/FAQ_c44c.asp#q1076q
Now what I am trying to do is to contain that code within the control class itself.  Any suggestions?

Thanks,
Kendal
0
jatinderalaghCommented:
You can do one thing write AutoGridSize as static metod in your class and pass the datagrid as variable to it.

public static void AutoSizeGrid(DataGrid dgr)

0
gvector1Author Commented:
Doesn't work.  Using GetType() still return a type of NewDataGrid(my custom datagrid).  When it is that type, the GetDataRows method cannot be accessed.
0
jatinderalaghCommented:
Got ur problem. Use the BaseType property for calling the method

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

Cheers
Jatinder
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jatinderalaghCommented:
And you can have it as instance member or static doesn't matter now
0
gvector1Author Commented:
Excellent,
Thanks jatinderalagh.  Just what I needed.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.