Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7633083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:47:07+00:00 2026-05-31T06:47:07+00:00

All, I have a GroupBox with multiple controls ( Button s, RadioButton s etc.)

  • 0

All, I have a GroupBox with multiple controls (Buttons, RadioButtons etc.) and I want to know the most efficent way of establishing which RadioButton in the GroupBox is in the checked state. I currently have

int nCheckedRadioIdx = 0;
foreach (Control ctrl in groupBoxList.Controls)
{
    if (ctrl.GetType() == typeof(RadioButton))
    {
        if (((RadioButton)ctrl).Checked)
        {
            switch (((RadioButton)ctrl).Name)
            { 
                case "radioButtonGoodCodeSumm":
                    nCheckedRadioIdx = 0;
                    break;
                case "radioButtonBadCodeSumm":
                    nCheckedRadioIdx = 1;
                    break;
                case "radioButtonBadByEpiNo":
                    nCheckedRadioIdx = 2;
                    break;
                case "radioButtonValidCodes":
                    nCheckedRadioIdx = 3;
                    break;
                default:
                    break;
            }
            break;
        }
    }
}

I then use an enumerator to establish which button I need. This seems very verbose to me (in fact damn ugly!). I have seen this done in VB with some sort of LINQ query (SO Question) but I have never worked with VB or LINQ and am struggling with the conversion. If there is an even better way that would be great as one of the GroupBoxs contains a significant number of RadioButtons – I would like to use LINQ for this if possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:47:08+00:00Added an answer on May 31, 2026 at 6:47 am

    Suppose you have, for each radiobutton THE SAME event handler that, when the button is checked set the Tag property of your GroupBox to the Tag of your RadioButton. At design time you set the Tag of the RadioButton to your desidered enum value. When you wish to retrieve your checked button you have only to read the Tag property without going through a loop (elegant or less) to check every control in your GroupBox.

    For example:

    private void RadioButton_Checked(oject sender, EventArgs e)
    {
        RadioButton radio = ((RadioButton)sender);
        if(radio.Checked)
            groupBoxList.Tag = radio.Tag;
    }
    

    Of course this will be efficient, but you should be sure to well document this because a change in the enum change will create problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have groupbox I want to clear all the control in it , I
I have several different lists I want to call. They all have the same
I have a WinForms Form with a few controls on it. All of them
I have sets of controls contained in individual GroupBox controls. So say GroupBoxCommon contains
I have a Windows Forms app that contains a groupbox with about 30 controls.
I have a series of tables which I want to all have an order
I have three classes that all have a static function called 'create'. I would
I have 50 newsletters which all have different email accouts, hex colour codes and
I have a database with Points of Interest that all have an address. I
I have a form[method=get] which has a number of checkboxes all have the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.