Results 1 to 2 of 2

Thread: C# Win App - Radiobutton if statements

  1. #1

    Thread Starter
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    Question C# Win App - Radiobutton if statements

    Code:
            //button to display branch name
            private void btnBranch_Click(object sender, EventArgs e)
            {
                //if no branch is selected
                if (rbtnKnight.Checked == false && rbtnWbldon.Checked == false && rbtnKston.Checked == false)
                {
                    //show error message
                    MessageBox.Show("Please select Branch!", "Error!");
                }
    
                else
                {
                    //if user selects knightsbridge branch
                    if (rbtnKnight.Checked == true)
                    {
                        txtBranch.Text = "Knightsbridge";
                        btnCost.Focus();        //sets focus in the Cost button when msg is displayed
                    }
    
                    //if user selects Wimbledon branch  
                    if (rbtnWbldon.Checked == true)
                    {
                        txtBranch.Text = "Wimbledon";
                        //set focus on btnCost once branch name is displayed
                        btnCost.Focus();
                    }
    
                    //if user selects Kingston branch
                    if (rbtnKston.Checked == true)
                    {
                        txtBranch.Text = "Kingston";
                        //set focus on btnCost once Kingston branch is displayed
                        btnCost.Focus();
                    }
                }
    
            }
    The radiobuttons are placed in a group box (grpBranch)

    Is there a way to make this better i.e making it to a switch statement?

    Thanx in advance

  2. #2
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Thumbs up Re: C# Win App - Radiobutton if statements

    Hello, maybe you can create an integer and set a value when the radio buttons are checked, and switch for that integer, good luck!
    C# and WPF developer
    My Website:
    http://singlebits.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width