I manage to get my code to work following the procedure described below,
http://www.pelennorfields.com/matt/2009/03/13/createdelegate-error-binding-to-target-method/
In essence, if I do the following, I get the error message "Error binding to the target method",
FAIL:
EventInfo eventClick = obj.GetType().GetEvent("TestClick");
Delegate handler = Delegate.CreateDelegate(
eventClick.EventHandlerType, this, "TestClick");
eventClick.AddEventHandler(obj, handler);
SUCCESS:
But when I changed it to:
MethodInfo methodOn_TestClick = this.GetType().GetMethod("TestClick", new Type[] { typeof(object), typeof(EventArgs));
Delegate handler = Delegate.CreateDelegate(
event_DomClick.EventHandlerType, this, methodOn_TestClick, true);
eventClick.AddEventHandler(obj, handler);
TestClick, EventArgs.
.
public void TestClick(object sender, EventArgs e)
{
PropertyInfo prop_ID = e.GetType().GetProperty("ID");
int id = Convert.toInt32(prop_ID.GetValue(e, null));
}