Unable to invoke protected method of DataGrid in Paint method
-
Hi, I found a code on net which allows multiline text in the datagrid cell. The sample code wasin VB.net, I just converted it to C#. Now the problem is the GetMethod is returning me null instead of an object. The code snippet is attached below
MethodInfo mi = dg.GetType().GetMethod("get_DataGridRows", BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); Array dgRowArray = (Array) mi.Invoke(this.dg, null);
the mi object is not getting created. It always says undefined. Am executing the above code in the overrided paint event of the datagrid. Can anyone help me out Any help is highly appreciated. Thanks in advance Regards, Kais -
Hi, I found a code on net which allows multiline text in the datagrid cell. The sample code wasin VB.net, I just converted it to C#. Now the problem is the GetMethod is returning me null instead of an object. The code snippet is attached below
MethodInfo mi = dg.GetType().GetMethod("get_DataGridRows", BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); Array dgRowArray = (Array) mi.Invoke(this.dg, null);
the mi object is not getting created. It always says undefined. Am executing the above code in the overrided paint event of the datagrid. Can anyone help me out Any help is highly appreciated. Thanks in advance Regards, KaisHello Kais, I also had problems with MethodInfo. So I changed my code too InvokeRequired, by using a delegate. private delegate void OnPaintDelegate(System.Windows.Forms.PaintEventArgs e); protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { if(InvokeRequired) { OnPaintDelegate(new OnPaintDelegate(_OnPaint), new object [] { e } ); return; } //Your code } Hope that helps you. All the best, Martin
-
Hello Kais, I also had problems with MethodInfo. So I changed my code too InvokeRequired, by using a delegate. private delegate void OnPaintDelegate(System.Windows.Forms.PaintEventArgs e); protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { if(InvokeRequired) { OnPaintDelegate(new OnPaintDelegate(_OnPaint), new object [] { e } ); return; } //Your code } Hope that helps you. All the best, Martin
-
Hi Martin, Where do we need to define "InvokeRequired" variable? Also i have override the paint method which has 7 parameters. Is that an issue? Please guide me if am wrong. I want to make this work. Regards, Kais
-
Hi Kais, InvokeRequired is a member of System.Windows.Forms.Control. You can have as much parameters as you whant, as long as your delagates has the same. private delegate void xxxDelegate(..., ..., ..., ...); Hope that helps you! All the best, Martin
Hi Martin, Thanks for your prompt reply. I added the peice of your code in my customized datagrid class which inherits from DataGrid. Now it throws me the following errors The name '_OnPaint' does not exist in the class or namespace CustomControl.CustomGrid.CustomDataGrid' CustomControl.CustomGrid.CustomDataGrid.OnPaintDelegate' denotes a 'class' which is not valid in the given context This might be a stupid thing i am asking. The delegate needs to be wrapped with the method. Where do i need to assign the method for it? Thanks in advance Regards, Kais
-
Hi Martin, Thanks for your prompt reply. I added the peice of your code in my customized datagrid class which inherits from DataGrid. Now it throws me the following errors The name '_OnPaint' does not exist in the class or namespace CustomControl.CustomGrid.CustomDataGrid' CustomControl.CustomGrid.CustomDataGrid.OnPaintDelegate' denotes a 'class' which is not valid in the given context This might be a stupid thing i am asking. The delegate needs to be wrapped with the method. Where do i need to assign the method for it? Thanks in advance Regards, Kais
Sorry, Was my mistake! private delegate void get_DataGridRowsDelegate(..., ..., ..., ...); protected override void get_DataGridRows(..., ..., ..., ...) { if(InvokeRequired) { get_DataGridRowsDelegate(new get_DataGridRowsDelegate(get_DataGridRows), new object [] { ..., ..., ..., ..., } ); return; } //Your code } The method has to be your get_DataGridRows Method you asked for. With all the parameters you had. If its not working, please post the code here! Martin -- modified at 8:08 Monday 3rd July, 2006
-
Hi Martin, Thanks for your prompt reply. I added the peice of your code in my customized datagrid class which inherits from DataGrid. Now it throws me the following errors The name '_OnPaint' does not exist in the class or namespace CustomControl.CustomGrid.CustomDataGrid' CustomControl.CustomGrid.CustomDataGrid.OnPaintDelegate' denotes a 'class' which is not valid in the given context This might be a stupid thing i am asking. The delegate needs to be wrapped with the method. Where do i need to assign the method for it? Thanks in advance Regards, Kais
-
Martin, Thats ok. But get_DataGridRows method is not available for override. How will this work? Regards, Kais
-
Martin, Thats ok. But get_DataGridRows method is not available for override. How will this work? Regards, Kais