Radio button, verify one is selected.

This is a discussion on Radio button, verify one is selected. within the C# Programming forums, part of the General Programming Boards category; Hello, I'm working on a project with radio buttons. It includes 12 radio buttons and before I run the program ...

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

    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
    52
    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
    2,370
    what GUI toolkit are you using? WPF? WinForms? something else?
    Code:
    namespace life
    {
        const bool change = true;
    }

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

  5. #5
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    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
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    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, 06: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, 05:58 AM
  4. Default checking of radio button in a group box
    By juhigarg in forum Windows Programming
    Replies: 3
    Last Post: 11-07-2001, 11:25 PM
  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21