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. Acting on an indeterminate checkbox checkstate

Acting on an indeterminate checkbox checkstate

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

    I'm setting up a search and I want the user to be able to decide if they want to see results based on a particular state of a boolean column in the table or ignore it and retrieve all rows regardless of the boolean state. (I hope that makes sense) Essentially I want the user to be able to set a checkbox as checked, unchecked, or indeterminate and have my program act on any three of these states. Is it possible to catch an indeterminate checkstate? If so, how? As far as I can tell, both checked and indeterminate return a true checked value, so I can't use null, and there is no checkstate value for indeterminate. Help! (Thanks in advance! Any help or advice would be tremendously appreciated!)

    D 1 Reply Last reply
    0
    • L Lodeclaw

      I'm setting up a search and I want the user to be able to decide if they want to see results based on a particular state of a boolean column in the table or ignore it and retrieve all rows regardless of the boolean state. (I hope that makes sense) Essentially I want the user to be able to set a checkbox as checked, unchecked, or indeterminate and have my program act on any three of these states. Is it possible to catch an indeterminate checkstate? If so, how? As far as I can tell, both checked and indeterminate return a true checked value, so I can't use null, and there is no checkstate value for indeterminate. Help! (Thanks in advance! Any help or advice would be tremendously appreciated!)

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      Check the CheckState property (no pun intended!).

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

      L 1 Reply Last reply
      0
      • D DaveyM69

        Check the CheckState property (no pun intended!).

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

        L Offline
        L Offline
        Lodeclaw
        wrote on last edited by
        #3

        Can you elaborate? It sounds as though you're telling me to do what I've already tried. I need a different action for all three checkstates: checked, unchecked and indeterminate.

        D 1 Reply Last reply
        0
        • L Lodeclaw

          Can you elaborate? It sounds as though you're telling me to do what I've already tried. I need a different action for all three checkstates: checked, unchecked and indeterminate.

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          Set the CheckBoxes ThreeState property to true, then use a switch to determine the search scope.

          switch (checkBox1.CheckState)
          {
          case CheckState.Checked:
          // do your thing
          break;
          case CheckState.Indeterminate:
          // do some other thing
          break;
          default: // Unchecked
          // do the Hokey Cokey
          break;
          }

          If you want the action to take place when the CheckBox is clicked, use the CheckStateChanged event, not the CheckedChanged as the latter doesn't respond to Indeterminate.

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

          L 1 Reply Last reply
          0
          • D DaveyM69

            Set the CheckBoxes ThreeState property to true, then use a switch to determine the search scope.

            switch (checkBox1.CheckState)
            {
            case CheckState.Checked:
            // do your thing
            break;
            case CheckState.Indeterminate:
            // do some other thing
            break;
            default: // Unchecked
            // do the Hokey Cokey
            break;
            }

            If you want the action to take place when the CheckBox is clicked, use the CheckStateChanged event, not the CheckedChanged as the latter doesn't respond to Indeterminate.

            Dave
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

            L Offline
            L Offline
            Lodeclaw
            wrote on last edited by
            #5

            Hm... That's interesting. Does this only work in a switch statement? I was trying to use an if statement with no success. Thank you for your help, Davey.

            D 1 Reply Last reply
            0
            • L Lodeclaw

              Hm... That's interesting. Does this only work in a switch statement? I was trying to use an if statement with no success. Thank you for your help, Davey.

              D Offline
              D Offline
              DaveyM69
              wrote on last edited by
              #6

              If statements will work fine

              if (checkBox1.CheckState == CheckState.Checked)
              {
              //
              }
              else if (checkBox1.CheckState == CheckState.Indeterminate)
              {
              //
              }
              else
              {
              //
              }

              Lodeclaw wrote:

              Thank you for your help

              No problem :)

              Dave
              BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
              Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

              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