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. Grouped Check Boxes

Grouped Check Boxes

Scheduled Pinned Locked Moved C#
question
8 Posts 4 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.
  • J Offline
    J Offline
    joshp1217
    wrote on last edited by
    #1

    Can you group together CheckBoxes so only one in a group is checked at one time and if so How?

    J E 2 Replies Last reply
    0
    • J joshp1217

      Can you group together CheckBoxes so only one in a group is checked at one time and if so How?

      J Offline
      J Offline
      Josh Smith
      wrote on last edited by
      #2

      Winforms or ASP.NET? If Winforms: Use RadioButtons instead of CheckBoxs. Put them in a GroupBox or Panel and they'll automatically be mutually exclusive. :josh: My WPF Blog[^]

      J 1 Reply Last reply
      0
      • J Josh Smith

        Winforms or ASP.NET? If Winforms: Use RadioButtons instead of CheckBoxs. Put them in a GroupBox or Panel and they'll automatically be mutually exclusive. :josh: My WPF Blog[^]

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

        Winforms, and i can't use Radion buttons because i am looking for the sticky button look that a check box has.

        J B 2 Replies Last reply
        0
        • J joshp1217

          Can you group together CheckBoxes so only one in a group is checked at one time and if so How?

          E Offline
          E Offline
          Ennis Ray Lynch Jr
          wrote on last edited by
          #4

          You deserve to be thrown off a cliff for doing so. Check box are designed so you can select multiple. Options are designed to choose. Switching the two will only confuse people. That said, create a collection of all of the check boxes you want to enforce one check only. Add a listener to all the check boxes for CheckedChanged to the same method. In the method loop through all of the check boxes in the collection if the sender object is a check box that is true and set all other check boxes to unchecked. A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

          E J 2 Replies Last reply
          0
          • E Ennis Ray Lynch Jr

            You deserve to be thrown off a cliff for doing so. Check box are designed so you can select multiple. Options are designed to choose. Switching the two will only confuse people. That said, create a collection of all of the check boxes you want to enforce one check only. Add a listener to all the check boxes for CheckedChanged to the same method. In the method loop through all of the check boxes in the collection if the sender object is a check box that is true and set all other check boxes to unchecked. A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

            E Offline
            E Offline
            Ennis Ray Lynch Jr
            wrote on last edited by
            #5

            private void checkBox_CheckedChanged(object sender, EventArgs e) {
            if(sender is CheckBox){
            if(((CheckBox)sender).Checked){
            foreach(CheckBox ck in list){
            if(ck != sender){ //Object comparison
            ck.Checked = false;
            }
            }
            }
            }
            }

            A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

            1 Reply Last reply
            0
            • E Ennis Ray Lynch Jr

              You deserve to be thrown off a cliff for doing so. Check box are designed so you can select multiple. Options are designed to choose. Switching the two will only confuse people. That said, create a collection of all of the check boxes you want to enforce one check only. Add a listener to all the check boxes for CheckedChanged to the same method. In the method loop through all of the check boxes in the collection if the sender object is a check box that is true and set all other check boxes to unchecked. A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

              J Offline
              J Offline
              joshp1217
              wrote on last edited by
              #6

              LMAO my bad, I'm sorry thanks for the help though sounds like a good solution

              1 Reply Last reply
              0
              • J joshp1217

                Winforms, and i can't use Radion buttons because i am looking for the sticky button look that a check box has.

                J Offline
                J Offline
                Josh Smith
                wrote on last edited by
                #7

                Your users will be confused by mutually exclusive checkboxes. It's atypical and, hence, weird. When it comes to UIs, stick to conventions unless you have a very good reason not to. :josh: My WPF Blog[^]

                1 Reply Last reply
                0
                • J joshp1217

                  Winforms, and i can't use Radion buttons because i am looking for the sticky button look that a check box has.

                  B Offline
                  B Offline
                  BoneSoft
                  wrote on last edited by
                  #8

                  What the hell is "sticky button look"? Can I use that next time I'm at the pool?


                  Try code model generation tools at BoneSoft.com.

                  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