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 8411319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:23:56+00:00 2026-06-10T00:23:56+00:00

I have three radio buttons. The code behind their change events is as follows:

  • 0

I have three radio buttons. The code behind their change events is as follows:

    private void uxRajRadioButton_CheckedChanged(object sender, EventArgs e) 
    {
        if (uxRajRadioButton.Checked == true)
        {
            uxPersonBettingLabel.Text = "Raj";
            GuySelected = 0;
            uxBetNumericUpDown.Maximum =  Guys[GuySelected].Cash;
        }
    }
    private void uxPaulRadioButton_CheckedChanged(object sender, EventArgs e) 
    {
        if (uxPaulRadioButton.Checked == true) 
        {
            uxPersonBettingLabel.Text = "Paul";
            GuySelected = 1;
            uxBetNumericUpDown.Maximum = Guys[GuySelected].Cash;
        }
    }
    private void uxMikeRadioButton_CheckedChanged(object sender, EventArgs e) 
    {
        if (uxMikeRadioButton.Checked == true)
        {
            uxPersonBettingLabel.Text = "Mike";
            GuySelected = 2;
            uxBetNumericUpDown.Maximum = Guys[GuySelected].Cash;
        }
    }

With just three radio buttons this is acceptable but if I had say 7 radio buttons each with 20 lines of code behind its change event then it would be a lot of (needless?) code. I’ve attempted to shorten the above and ended up with the following. Is this correct?

     private void uxRajRadioButton_CheckedChanged(object sender, EventArgs e) 
    { 
         radioButtonCode(this.uxRajRadioButton, 0);
     }
    private void uxPaulRadioButton_CheckedChanged(object sender, EventArgs e) 
    {
        radioButtonCode(this.uxPaulRadioButton,1);
    }
    private void uxMikeRadioButton_CheckedChanged(object sender, EventArgs e) 
    {
        radioButtonCode(this.uxMikeRadioButton, 2);
    }

    int GuySelected=0;
    public void radioButtonCode(RadioButton myRadio, int mybettorIndex)
    {
        if (myRadio.Checked == true)
        {
            GuySelected = mybettorIndex;
            uxPersonBettingLabel.Text = Guys[GuySelected].Name;
            uxBetNumericUpDown.Maximum = Guys[GuySelected].Cash;
        }
    }
  • 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-06-10T00:23:56+00:00Added an answer on June 10, 2026 at 12:23 am

    Could you have the same event handler for all the radio buttons? Something like

    private void uxRadioButton_CheckedChanged(object sender, EventArgs e) 
    { 
         radioButtonCode((RadioButton)sender);
    }
    
    public void radioButtonCode(RadioButton myRadio)
    {
        if (myRadio.Checked == true)
        {
            int guySelected = getGuySelectedIndex(myRadio);
            uxPersonBettingLabel.Text = Guys[guySelected].Name;
            uxBetNumericUpDown.Maximum = Guys[guySelected].Cash;
        }
    }
    
    public int getGuySelectedIndex(RadioButton myRadio)
    {
        int index = 0;
        if (myRadio == this.uxRajRadioButton) index = 0;
        else if (myRadio == this.uxPaulRadioButton) index = 1;
        else if (myRadio == this.uxMikeRadioButton) index = 2;
        return index;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three radio buttons with same name and different values.When I click the
In my page I have three radio buttons and I want to checked the
I have a group of three radio buttons. Depending on which radio button is
I have the following code in jQuery for a set of radio buttons which
I have a form in as3 flash with textfields and radio buttons with their
I have a series of radio buttons (rdoGroup1,rdoGroup2,rdoGroup3) and three textboxes at the end
I have three radio buttons in a search group: Zip, City and County. How
Hi all i am working on jquery here i have three three radio buttons
I have three radio buttons and a textfield generated by drupal. What I want
I have 3 file uploads and three radio buttons associated with them. All radio

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.