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. CheckedListBox state to property

CheckedListBox state to property

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

    Can you directly store the CheckState.Checked / Unchecked value in a class property? If so how would you store it, or do I have to examine it and store a bool? Thanks.

    P D 2 Replies Last reply
    0
    • B BDJones

      Can you directly store the CheckState.Checked / Unchecked value in a class property? If so how would you store it, or do I have to examine it and store a bool? Thanks.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      I don't think so, but you can attach a handler for the ItemCheck event.

      1 Reply Last reply
      0
      • B BDJones

        Can you directly store the CheckState.Checked / Unchecked value in a class property? If so how would you store it, or do I have to examine it and store a bool? Thanks.

        D Offline
        D Offline
        dan sh
        wrote on last edited by
        #3

        If you need to track the checked items in the control, you can make use of CheckedIndices property.

        50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

        B 1 Reply Last reply
        0
        • D dan sh

          If you need to track the checked items in the control, you can make use of CheckedIndices property.

          50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

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

          So you cannot store the e.CheckState value in the ItemCheck event? I have many collections to display/redisplay in the same checkedlistbox. I would rather push a value to the object in the list when it is checked then cycle through all of them before changing the collection being displayed. I have

          if (e.NewValue == CheckState.Checked)
          dv.checkedInLB = true;
          else
          dv.checkedInLB = false;

          which works fine, but adds a step.

          P D 2 Replies Last reply
          0
          • B BDJones

            So you cannot store the e.CheckState value in the ItemCheck event? I have many collections to display/redisplay in the same checkedlistbox. I would rather push a value to the object in the list when it is checked then cycle through all of them before changing the collection being displayed. I have

            if (e.NewValue == CheckState.Checked)
            dv.checkedInLB = true;
            else
            dv.checkedInLB = false;

            which works fine, but adds a step.

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            I haven't tried it, but I would expect something like: ((SomeType)checkedListBox1.SelectedItem).checkedInLB = e.NewValue == CheckState.Checked ;

            1 Reply Last reply
            0
            • B BDJones

              So you cannot store the e.CheckState value in the ItemCheck event? I have many collections to display/redisplay in the same checkedlistbox. I would rather push a value to the object in the list when it is checked then cycle through all of them before changing the collection being displayed. I have

              if (e.NewValue == CheckState.Checked)
              dv.checkedInLB = true;
              else
              dv.checkedInLB = false;

              which works fine, but adds a step.

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #6

              If you keep the checked state in some other property, you will be checking that then. So any ways you will have to check by some mean or the another that check box is checked or not. Am I understanding your problem correct or not? I assume you want to store checkedstate in a boolean property. Like:

              if (checkedListBox.Items[index].checked){
              // do something
              }
              else{
              // do something else
              }

              50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

              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