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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. parameter in Event Handler

parameter in Event Handler

Scheduled Pinned Locked Moved C#
question
5 Posts 3 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.
  • S Offline
    S Offline
    Saiyed Alam
    wrote on last edited by
    #1

    Hello,, Is it possible to send a parameter like below?

    CheckBox oCheckBox = new CheckBox();
    oCheckBox.Name = "cb_" + currentChild.ID;
    oCheckBox.Click += new RoutedEventHandler(this.CheckClick);

    Now I want to send the name of check box to the event handler. HOw can I do it? Like

    CheckBox oCheckBox = new CheckBox();
    oCheckBox.Name = "cb_" + currentChild.ID;
    oCheckBox.Click += new RoutedEventHandler(this.CheckClick,oCheckBox.Name);

    so that in

    CheckClick(object sender, RoutedEventArgs e)

    I can get the name of that check box as there will be many dynamically created check box.

    K J 2 Replies Last reply
    0
    • S Saiyed Alam

      Hello,, Is it possible to send a parameter like below?

      CheckBox oCheckBox = new CheckBox();
      oCheckBox.Name = "cb_" + currentChild.ID;
      oCheckBox.Click += new RoutedEventHandler(this.CheckClick);

      Now I want to send the name of check box to the event handler. HOw can I do it? Like

      CheckBox oCheckBox = new CheckBox();
      oCheckBox.Name = "cb_" + currentChild.ID;
      oCheckBox.Click += new RoutedEventHandler(this.CheckClick,oCheckBox.Name);

      so that in

      CheckClick(object sender, RoutedEventArgs e)

      I can get the name of that check box as there will be many dynamically created check box.

      K Offline
      K Offline
      Keith Barrow
      wrote on last edited by
      #2

      One of the following lines should work, with the caveat that I'm a little rusty on WPF, so apologies if my answer isn't correct!

      CheckClick(object sender, RoutedEventArgs e)
      {
      CheckBox checkBox1 = (CheckBox)sender;
      sring id = checkBox1.Name;
      // or
      CheckBox checkBox2 = (CheckBox)e.OriginalSource;
      sring id = checkBox2.Name;
      }

      S 1 Reply Last reply
      0
      • S Saiyed Alam

        Hello,, Is it possible to send a parameter like below?

        CheckBox oCheckBox = new CheckBox();
        oCheckBox.Name = "cb_" + currentChild.ID;
        oCheckBox.Click += new RoutedEventHandler(this.CheckClick);

        Now I want to send the name of check box to the event handler. HOw can I do it? Like

        CheckBox oCheckBox = new CheckBox();
        oCheckBox.Name = "cb_" + currentChild.ID;
        oCheckBox.Click += new RoutedEventHandler(this.CheckClick,oCheckBox.Name);

        so that in

        CheckClick(object sender, RoutedEventArgs e)

        I can get the name of that check box as there will be many dynamically created check box.

        J Offline
        J Offline
        Jacobb Michael
        wrote on last edited by
        #3

        Just try with this. CheckClick(object sender, RoutedEventArgs e) { string chkBoxName = ((CheckBox)sender).Name; }

        S 1 Reply Last reply
        0
        • K Keith Barrow

          One of the following lines should work, with the caveat that I'm a little rusty on WPF, so apologies if my answer isn't correct!

          CheckClick(object sender, RoutedEventArgs e)
          {
          CheckBox checkBox1 = (CheckBox)sender;
          sring id = checkBox1.Name;
          // or
          CheckBox checkBox2 = (CheckBox)e.OriginalSource;
          sring id = checkBox2.Name;
          }

          S Offline
          S Offline
          Saiyed Alam
          wrote on last edited by
          #4

          Thanks ..

          1 Reply Last reply
          0
          • J Jacobb Michael

            Just try with this. CheckClick(object sender, RoutedEventArgs e) { string chkBoxName = ((CheckBox)sender).Name; }

            S Offline
            S Offline
            Saiyed Alam
            wrote on last edited by
            #5

            Thanks ..It Worked

            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