S
Skandy
Hello All:
My second post in as many days! I'm trying to get this working.
I have a form and a user control and trying to add the user control to
this form. Without reflection this would be achieved as
Form.Controls.Add(objUserControl);
Now in my code I have the following:
objUserControl = User Control Object obtained by reflection.
mi is the MethodInfo for the Add method obtained as:
MethodInfo mi = piProp.GetSetMethod();
mi = piProp.PropertyType.GetMethod("Add");
objUserControl.GetType().BaseType returns System.Windows.Forms.Control.
I want to get this working:
mi.Invoke(objForm, new object[] {objUserControl });
But it wouldnt let me as objUserControl causes a
TargetInvocationException. Please let me know how I can handle this.
The end result should be the same as:
Form.Controls.Add(objUserControl);
I know this should be something quite simple, but I'm clearly missing
something and am new to reflection.
Thanks in Advance.
Skanda
My second post in as many days! I'm trying to get this working.
I have a form and a user control and trying to add the user control to
this form. Without reflection this would be achieved as
Form.Controls.Add(objUserControl);
Now in my code I have the following:
objUserControl = User Control Object obtained by reflection.
mi is the MethodInfo for the Add method obtained as:
MethodInfo mi = piProp.GetSetMethod();
mi = piProp.PropertyType.GetMethod("Add");
objUserControl.GetType().BaseType returns System.Windows.Forms.Control.
I want to get this working:
mi.Invoke(objForm, new object[] {objUserControl });
But it wouldnt let me as objUserControl causes a
TargetInvocationException. Please let me know how I can handle this.
The end result should be the same as:
Form.Controls.Add(objUserControl);
I know this should be something quite simple, but I'm clearly missing
something and am new to reflection.
Thanks in Advance.
Skanda