Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Error when using delegate.... ( Error in binding the target method)...

Error when using delegate.... ( Error in binding the target method)...

Scheduled Pinned Locked Moved C#
wpfwcfgraphicshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    peter rankel
    wrote on last edited by
    #1

    Hi... My requirement is to retrieve the child form values into parent form in windows application. For this I am using delegate . And i m getting the following error: " An unhandled exception of type 'System.NullReferenceException' occurred in Delegates.exe Additional information: Error binding to target method. " Please give me the solution if anyone knows . Its urgent. Code which I have written is: Parent Form: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace Delegates { public class Form1 : System.Windows.Forms.Form { private string str; public string strPro { set { str=value; } get { return str; } } public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } public void fncForm1Test() { textBox1.Text="Hi"; } private void button1_Click(object sender, System.EventArgs e) { Form2 obj2=new Form2(); obj2.Owner=this; obj2.ParentMain = (Form)this.Owner;//Giving ownership ePCRCustomizeControl page to Main page obj2.HostForm = this;//Giving ownership ePCRCustomizeControl page to ePCR_BtnCompositeControl page obj2.Show(); } } } Child Form: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace Delegates { public class Form2 : System.Windows.Forms.Form { public delegate void MyDelegate(); private Form _Parent; public Form ParentMain { get { return _Parent; } set { _Parent = value; } } private Form _Host; public Form HostForm { get { return _Host; } set { _Host = value; } } public Form2() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); }

    C 1 Reply Last reply
    0
    • P peter rankel

      Hi... My requirement is to retrieve the child form values into parent form in windows application. For this I am using delegate . And i m getting the following error: " An unhandled exception of type 'System.NullReferenceException' occurred in Delegates.exe Additional information: Error binding to target method. " Please give me the solution if anyone knows . Its urgent. Code which I have written is: Parent Form: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace Delegates { public class Form1 : System.Windows.Forms.Form { private string str; public string strPro { set { str=value; } get { return str; } } public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } public void fncForm1Test() { textBox1.Text="Hi"; } private void button1_Click(object sender, System.EventArgs e) { Form2 obj2=new Form2(); obj2.Owner=this; obj2.ParentMain = (Form)this.Owner;//Giving ownership ePCRCustomizeControl page to Main page obj2.HostForm = this;//Giving ownership ePCRCustomizeControl page to ePCR_BtnCompositeControl page obj2.Show(); } } } Child Form: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace Delegates { public class Form2 : System.Windows.Forms.Form { public delegate void MyDelegate(); private Form _Parent; public Form ParentMain { get { return _Parent; } set { _Parent = value; } } private Form _Host; public Form HostForm { get { return _Host; } set { _Host = value; } } public Form2() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); }

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      peter rankel wrote:

      Please give me the solution if anyone knows . Its urgent.

      Of course it is... But not enough for you to post some code that points out the exact error, instead of the whole project ?

      peter rankel wrote:

      obja=new MyDelegate(objForm1.fncForm1Test); obja();

      This is weird code, what is it trying to achieve ?

      peter rankel wrote:

      Form1 objForm1=(Form1)_Parent;

      As far as I can see, you should make _Parent an instance of Form1, instead of assuming it is and then trying to cast it.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups