4 Replies - 7065 Views - Last Post: 19 July 2009 - 08:56 AM Rate Topic: -----

#1 majc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-July 09

Error binding to target method

Posted 18 July 2009 - 06:12 PM

		private void Record_Click(object sender, EventArgs e)
		{
			string[] eventsName = getSelectedEvents();
			string[] controlName = getSelectedControls();
			for (int i = 0; i < controlName.Length; i++)
			{
				Control ctrl = controls[controlName[i]];
				foreach (EventInfo eventCtrl in ctrlEvents)
				{
					foreach (string eventName in eventsName)
					{
						if (eventCtrl.Name == eventName)
						{
							Type tDelegate = eventCtrl.EventHandlerType;
							MethodInfo methodToRegister = typeof(FormRecorder).GetMethod("registerInEventsList", BindingFlags.NonPublic | BindingFlags.Instance);
							Delegate d = Delegate.CreateDelegate(tDelegate, ctrl, methodToRegister);
							MethodInfo addHandler = eventCtrl.GetAddMethod();
							Object[] addHandlerArgs = { d };
							addHandler.Invoke(this, addHandlerArgs);
						}
					}
				}
			}
			Form1 form1 = new Form1();
			form1.Show();
		}


ctrl is the control where i'm trying to raise the event, but Delegate d = Delegate.CreateDelegate(tDelegate, ctrl, methodToRegister); gives the following error: "Error binding to target method" if i use "this"(form) instead of the control works fine. Can someone help me with this?

Is This A Good Question/Topic? 0
  • +

Replies To: Error binding to target method

#2 sknake  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 15-July 09

Re: Error binding to target method

Posted 19 July 2009 - 05:50 AM

Cross post:
http://www.daniweb.c...read205077.html
Was This Post Helpful? 0
  • +
  • -

#3 majc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-July 09

Re: Error binding to target method

Posted 19 July 2009 - 07:21 AM

View Postsknake, on 19 Jul, 2009 - 04:50 AM, said:


And solution? No? :)

This post has been edited by majc: 19 July 2009 - 07:22 AM

Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Error binding to target method

Posted 19 July 2009 - 07:28 AM

View Postsknake, on 19 Jul, 2009 - 07:50 AM, said:



Is there a problem with posting it on multiple forums? As long as he isn't cluttering this forum with multiple posts, I don't see a problem with it. It's the best way to get the most people to see it to get a possible answer.
Was This Post Helpful? 0
  • +
  • -

#5 majc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-July 09

Re: Error binding to target method

Posted 19 July 2009 - 08:56 AM

Yes i think the same :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1