Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
How to use a switch case statement in conjunction with a group box in c#?

I am new to C# and I am trying to check which one of seven radio button within a group box is checked. The line with the "case" is giving me trouble. I am able to make it work using multiple if statements, but I would like to know if a switch statement would work too. Thanks for your help! Here is the code snippet:

      {
          if (OptMaennlich.Checked == true)
          {
              double Grundumsatz = (double)NumGewicht.Value * 24;
              switch (GrpAktivitaet)
              {
                  case OptSchlafen.Checked == true
                      double PAL = 1.0;
                      break;

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you are still stuck and you are using Windows Forms, I would suggest subscribing to the CheckedChanged event either in the properties inspector or in the code behind for each of the radio buttons you have in your groupbox. Switching on the Text Property of the RadioButton is one way of achieving this in the event.

In your initialisation code:

OptSchlafen.CheckedChanged += SomeFunctionToCheckChangedState;

and in your code a function:

private void SomeFunctionToCheckChangedState(object sender, EventArgs e)
{
    // Insert your check logic here
    switch((sender as RadioButton).Text)
    {
        case "radiobuttontext":
            //what you want to do goes here
        break;
    }
}

When you click the radio button this event will be fired and the function called.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!