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. triggering events by code

triggering events by code

Scheduled Pinned Locked Moved C#
4 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.
  • M Offline
    M Offline
    Mridang Agarwalla
    wrote on last edited by
    #1

    i have a checkbox on my form and i have written a few lines of code on the checkbox.checkchanged event which fires everytime u check or uncheck the box. This works fine till u check it by clicking on it at runtime but the event doesnt fire when I type checkbox.checked = true. How cn i make the event fire through code..

    J 1 Reply Last reply
    0
    • M Mridang Agarwalla

      i have a checkbox on my form and i have written a few lines of code on the checkbox.checkchanged event which fires everytime u check or uncheck the box. This works fine till u check it by clicking on it at runtime but the event doesnt fire when I type checkbox.checked = true. How cn i make the event fire through code..

      J Offline
      J Offline
      Jay Shankar
      wrote on last edited by
      #2

      If checkbox.Checked is already true, and you write the checkbox.checked = true, then checkbox.checkchanged will not fire, since the checkState is not being changed, Otherwise it will fire. Check using the statement like

      this.checkbox.Checked = !this.checkbox.Checked;

      BTW, If you want to call the eventHandler from any where else call like below

      this.checkBox1_CheckedChanged(this, new System.EventArgs());

      M 1 Reply Last reply
      0
      • J Jay Shankar

        If checkbox.Checked is already true, and you write the checkbox.checked = true, then checkbox.checkchanged will not fire, since the checkState is not being changed, Otherwise it will fire. Check using the statement like

        this.checkbox.Checked = !this.checkbox.Checked;

        BTW, If you want to call the eventHandler from any where else call like below

        this.checkBox1_CheckedChanged(this, new System.EventArgs());

        M Offline
        M Offline
        Mridang Agarwalla
        wrote on last edited by
        #3

        hi jay, my code doesnt seem to fire when i type checkbox1.checked = true; even thouhg my checkbox state is false. please subscribe to this thread so i can reply

        J 1 Reply Last reply
        0
        • M Mridang Agarwalla

          hi jay, my code doesnt seem to fire when i type checkbox1.checked = true; even thouhg my checkbox state is false. please subscribe to this thread so i can reply

          J Offline
          J Offline
          Jay Shankar
          wrote on last edited by
          #4

          Hi Mridang, First of all, please go through the msdn documents CheckBox.CheckedChanged[^] It should fire. There is no bug in the .net, concerning this. As I said in my previous post, check using again.

          this.checkbox.Checked = !this.checkbox.Checked;

          or

          private void ChangeCheckBoxState(CheckBox cbx)
          {
          cbx.Checked = !cbx.Checked;

          System.Diagnostics.Debug.WriteLine("checked state transformed to  " + this.checkBox1.Checked);
          

          }

          //

          private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
          {
          MessageBox.Show("Check Changed");

          }

          You can explicitly also call the event handler, just to reconfirm as

          this.checkBox1_CheckedChanged(this, new System.EventArgs());

          I would also advice you to prepare a simple demo project to check the above phenomenon. Regards, Jay.

          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