Thread: Radio button, verify one is selected.

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    53

    Radio button, verify one is selected.

    Hello,

    I'm working on a project with radio buttons. It includes 12 radio buttons and before I run the program I need to verify that one of the buttons is selected. Is there an easy way of doing this?

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    53
    Below is what I did, anyone has any other suggestions?

    Code:
           private void RadioSelected()
            {
                if (!(this.radioButton1.Checked || this.radioButton2.Checked || this.radioButton3.Checked ||
                    this.radioButton4.Checked || this.radioButton5.Checked || this.radioButton6.Checked ||
                    this.radioButton7.Checked || this.radioButton8.Checked))
                {
                    MessageBox.Show("Select at least one RadioButton");
                    return;
                }
    
            }

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    what GUI toolkit are you using? WPF? WinForms? something else?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    53
    Quote Originally Posted by Elkvis View Post
    what GUI toolkit are you using? WPF? WinForms? something else?
    WinForms

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    I usually initialize one of every set of radio buttons as selected. Barring strangeness like the code directly clearing the radio button, it shouldn't from then be possible to deselect all buttons.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Bind the radio buttons (2 state?) to Boolean properties in your class. Check the boolean property to see if the radio button is selected.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Radio button is it checked?
    By Bajanine in forum Windows Programming
    Replies: 2
    Last Post: 11-21-2002, 07:08 PM
  2. Radio button linked to text box
    By J_Bravo in forum Windows Programming
    Replies: 9
    Last Post: 05-07-2002, 10:15 PM
  3. Unselecting a radio button
    By canine in forum Windows Programming
    Replies: 1
    Last Post: 11-27-2001, 06:58 AM
  4. Default checking of radio button in a group box
    By juhigarg in forum Windows Programming
    Replies: 3
    Last Post: 11-08-2001, 12:25 AM
  5. Unselecting a selected button in C++Builder 5
    By Frozen_solid in forum Windows Programming
    Replies: 4
    Last Post: 09-25-2001, 07:57 PM