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 limiting. [modified]

CheckBox limiting. [modified]

Scheduled Pinned Locked Moved C#
csstutorialquestion
4 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.
  • G Offline
    G Offline
    Gregory Bryant
    wrote on last edited by
    #1

    So I hope this has a Simple answer. I have a program with 6 Options, they can be either RadioButtons or CheckBoxs, But I need to know how to limit the options to 3 or less? Is there an easy way to do this with out checking how many are true and building a checker?

    modified on Thursday, October 15, 2009 11:15 AM

    L 1 Reply Last reply
    0
    • G Gregory Bryant

      So I hope this has a Simple answer. I have a program with 6 Options, they can be either RadioButtons or CheckBoxs, But I need to know how to limit the options to 3 or less? Is there an easy way to do this with out checking how many are true and building a checker?

      modified on Thursday, October 15, 2009 11:15 AM

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

      Hi, I have no idea what you mean by ControlButtons, did you mean CheckBoxes? Anyway, the only way I know would be to attach this same handler to each of the relevant Controls; then either have a collection that holds the relevant controls or tag them somehow so you can easily enumerate them:

      void CheckedChanged(object sender, EventArgs e) {
      int count=0;
      foreach(Control c in relevantControls) {
      RadioButton rb=c as RadioButton;
      if (rb!=null) count++;
      }
      if (count>MAX) {
      RadioButton rb=sender as RadioButton;
      if (rb!=null) rb.Checked=false;
      }
      }

      :)

      Luc Pattyn


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


      Local announcement (Antwerp region): Lange Wapper? Neen!


      G 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, I have no idea what you mean by ControlButtons, did you mean CheckBoxes? Anyway, the only way I know would be to attach this same handler to each of the relevant Controls; then either have a collection that holds the relevant controls or tag them somehow so you can easily enumerate them:

        void CheckedChanged(object sender, EventArgs e) {
        int count=0;
        foreach(Control c in relevantControls) {
        RadioButton rb=c as RadioButton;
        if (rb!=null) count++;
        }
        if (count>MAX) {
        RadioButton rb=sender as RadioButton;
        if (rb!=null) rb.Checked=false;
        }
        }

        :)

        Luc Pattyn


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


        Local announcement (Antwerp region): Lange Wapper? Neen!


        G Offline
        G Offline
        Gregory Bryant
        wrote on last edited by
        #3

        Yea I meant CheckBoxs or RadioButtons sorry, and yea I was looking for a way other than that.

        S 1 Reply Last reply
        0
        • G Gregory Bryant

          Yea I meant CheckBoxs or RadioButtons sorry, and yea I was looking for a way other than that.

          S Offline
          S Offline
          Saksida Bojan
          wrote on last edited by
          #4

          You have your answers, But let me tell you there is big difrance betwen CheckBox and RadioBox You can have a lot of checkBoxex. Each check box can be true or false If you have more than 1 RadioBox, you can set it to true to ONLY ONE. To seperate betwen radioboxex (aka Grouping) place it in a panel Edit: You can't check it without programming it. You need to check how many has ben set to true. There is no build in functions for your request

          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