I built a windows control which inherits from the windows datagrid
class
Public Class XDataGrid
Inherits System.Windows.Forms.DataGrid
Private _AutoSizeDataGrid As Boolean
Private _AutosizeColumns As Boolean
..
..
..
..
I have found some code which can be used to autosize the columns in a
windows datagrid. This works fine if you put the code in a form.
However I want to put the code in my custom control (xdatagrid) and
have it work on my base (inherited) datagrid class.
Here is the code
1 Dim t As Type = MyBase.GetType
2 Dim m As Reflection.MethodInfo = t.GetMethod("ColAutoResize",
Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance)
3 Dim i As Integer = MyBase.FirstVisibleColumn
4 Dim j As Integer = MyBase.VisibleColumnCount
6 Do While i < j
7 m.Invoke(MyBase, New Object() {i})
8 i = i + 1
9 Loop
The problem is that line 7 expects to invoke the method on a datagrid
object. However, I cannot get a reference to the underlying datagrid
object that my xDatagrid inherits from.
Me will reference my xdatagrid object which doesn't work
Mybase will work for lines 1,2,3 and 4 but m.Invoke won't except
Mybase as a parameter.
Anyone out there who can make this work?
Erick