Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we uncheck a radio button [closed]

Tags:

c#

.net

I want to know how can we uncheck a radio button. It should work like a checkbox.

like image 635
Running Rabbit Avatar asked May 22 '12 08:05

Running Rabbit


People also ask

How do I uncheck a radio button?

To set a radio button to checked/unchecked, select the element and set its checked property to true or false , e.g. myRadio. checked = true .

How do you uncheck a radio button React?

To uncheck radio buttons in React, we can set the checked prop of the radio button to false . We have the checked state that we use to set the checked prop of each radio button.


3 Answers

This might work:

private void radio_click(object sender, EventArgs e)
{
  if (radio.Checked)
  {
    radio.Checked = false;
  }
}
like image 59
Milan Halada Avatar answered Oct 17 '22 09:10

Milan Halada


Use the following code to use radio button like check box.

    bool isChecked =false;
    private void radioButton1_CheckedChanged(object sender, EventArgs e)
    {
        isChecked = radioButton1.Checked;
    }

    private void radioButton1_Click(object sender, EventArgs e)
    {
        if (radioButton1.Checked && !isChecked)
            radioButton1.Checked = false;
        else
        {
            radioButton1.Checked = true;
            isChecked = false;
        }
    }
like image 27
Shiv Sahu Avatar answered Oct 17 '22 07:10

Shiv Sahu


Radio buttons are used when you want the user to choose, usually, one or more items from a series of options, so by the end, you will have at least one selected item. If you want to provide the user to uncheck, then, you should really be using a Checkbox in the first place.

At most in your case, you could provide some functionality such as a button to reset the radio buttons, by doing something like rdBtn.Checked = false;

like image 43
npinti Avatar answered Oct 17 '22 08:10

npinti