Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

WPF switch between 2 Check boxes

**
I am trying to make an if statement to switch the checked box between each other
Image of check boxes
here is what I got so far:**


        private void offline_CheckedChanged(object sender, EventArgs e)
        {
            offline.Checked = true;
            if (bot.Checked == true)
            {
                bot.Checked = false;
            }
        }

        private void bot_CheckedChanged(object sender, EventArgs e)
        {
            bot.Checked = true;
            if (offline.Checked == true)
            {
                offline.Checked = false;
            }
        }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you want only one of them to be checked at a time, you could use the negated values:

private void offline_CheckedChanged(object sender, EventArgs e)
{
    bot.Checked = !offline.Checked;
}

private void bot_CheckedChanged(object sender, EventArgs e)
{
    offline.Checked = !bot.Checked;
}

Keep in mind that you’d have to change their initial values if you want this behavior from the start of the application

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading