?
Solved

DataGrid Question

Posted on 2005-03-28
13
Medium Priority
?
287 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:gvector1
[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
  • 6
  • 4
  • 3
13 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13647032
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
 

Author Comment

by:gvector1
ID: 13647092
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13647121
So, when does this code get called?

Bob
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:gvector1
ID: 13647148
Pretty much anytime the datagrid is redrawn.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13647166
What is dg1 (variable instance)?  Where is dgra used?

Bob
0
 

Author Comment

by:gvector1
ID: 13652539
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13653110
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
 

Author Comment

by:gvector1
ID: 13653151
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
 
LVL 11

Expert Comment

by:jatinderalagh
ID: 13659420
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
 

Author Comment

by:gvector1
ID: 13662587
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
 
LVL 11

Accepted Solution

by:
jatinderalagh earned 2000 total points
ID: 13668431
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
 
LVL 11

Expert Comment

by:jatinderalagh
ID: 13668455
And you can have it as instance member or static doesn't matter now
0
 

Author Comment

by:gvector1
ID: 13671931
Excellent,
Thanks jatinderalagh.  Just what I needed.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

801 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