Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

DataGrid Question

Posted on 2005-03-28
13
Medium Priority
?
291 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

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!

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

580 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