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. Checkbox & CheckedChanged event... really?

Checkbox & CheckedChanged event... really?

Scheduled Pinned Locked Moved C#
question
6 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.
  • B Offline
    B Offline
    BDJones
    wrote on last edited by
    #1

    When the CheckedChanged event fires, why does e not have a property with the current state? A CheckedListbox does... Am I missing something here? private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)... >>e has 'currentValue' and 'newValue'<< private void checkBox1_CheckedChanged(object sender, EventArgs e)... >>e has doesn't<< Do I really have to go get the state from the checkbox when I'm already in the state event fired by that checkbox? (checkBox1 == true) That seems redundant. Thanks.

    L J 2 Replies Last reply
    0
    • B BDJones

      When the CheckedChanged event fires, why does e not have a property with the current state? A CheckedListbox does... Am I missing something here? private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)... >>e has 'currentValue' and 'newValue'<< private void checkBox1_CheckedChanged(object sender, EventArgs e)... >>e has doesn't<< Do I really have to go get the state from the checkbox when I'm already in the state event fired by that checkbox? (checkBox1 == true) That seems redundant. Thanks.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      BDJones wrote:

      Do I really have to go get the state from the checkbox

      yes

      BDJones wrote:

      if (checkBox1 == true) ...

      no if (checkBox1.Checked) ... :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      B 1 Reply Last reply
      0
      • B BDJones

        When the CheckedChanged event fires, why does e not have a property with the current state? A CheckedListbox does... Am I missing something here? private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)... >>e has 'currentValue' and 'newValue'<< private void checkBox1_CheckedChanged(object sender, EventArgs e)... >>e has doesn't<< Do I really have to go get the state from the checkbox when I'm already in the state event fired by that checkbox? (checkBox1 == true) That seems redundant. Thanks.

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        The reason the checkedlistbox passes the state is because there are any number of individual checkboxes which may be checked/unchecked. A single checkbox is passed to you in the event

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
        CheckBox chkBox = (CheckBox)sender;
        if(chkBox.Checked) ...
        }

        B 2 Replies Last reply
        0
        • J J4amieC

          The reason the checkedlistbox passes the state is because there are any number of individual checkboxes which may be checked/unchecked. A single checkbox is passed to you in the event

          private void checkBox1_CheckedChanged(object sender, EventArgs e)
          {
          CheckBox chkBox = (CheckBox)sender;
          if(chkBox.Checked) ...
          }

          B Offline
          B Offline
          BDJones
          wrote on last edited by
          #4

          Thank you.

          1 Reply Last reply
          0
          • L Luc Pattyn

            BDJones wrote:

            Do I really have to go get the state from the checkbox

            yes

            BDJones wrote:

            if (checkBox1 == true) ...

            no if (checkBox1.Checked) ... :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


            B Offline
            B Offline
            BDJones
            wrote on last edited by
            #5

            OK, thanks.

            1 Reply Last reply
            0
            • J J4amieC

              The reason the checkedlistbox passes the state is because there are any number of individual checkboxes which may be checked/unchecked. A single checkbox is passed to you in the event

              private void checkBox1_CheckedChanged(object sender, EventArgs e)
              {
              CheckBox chkBox = (CheckBox)sender;
              if(chkBox.Checked) ...
              }

              B Offline
              B Offline
              BDJones
              wrote on last edited by
              #6

              Would you mind educating me a little more... What exactly is happening here? (Checkbox)sender; Is this casting sender as a Checkbox?

              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