Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my c# application, I need radiobutton, but if the user clicks a radio button they can't unclick them (so it becomes mandatory once they've chosen one). I can not unclick them. can some one give the idea?
Posted
Comments
[no name] 21-Oct-14 1:53am    
asp .net or winform ?
Member 10984793 21-Oct-14 2:04am    
win form

You should use CheckBox instead. RadioButtons are meant to be chose.

However look at the answer - How can we uncheck a radio button[^].
 
Share this answer
 
Comments
Member 10984793 21-Oct-14 2:33am    
thanks
Welcome. :)
I suggest you evaluate whether CheckBoxes meet your needs in this design scenario.

RadioButtons are meant to be used in groups ... for example, all the RadioButtons in a WinForms Panel are a "group" ... where one of them will always have its CheckState Property set to 'Checked.

By designing your user-interface using the Microsoft Windows User Interface Guidelines, you will presenting users with interactive they are familiar with. Here's guidelines for RadioButtons: [^].

In WinForms it is, perhaps, an inconsistent behavior that a bunch of RadioButtons put in some ContainerControl, or on a Form, initially appear at design-time, and then at run-time, as all unchecked unless you have at design-time set the checked property of one of them.
 
Share this answer
 
Comments
Member 10984793 21-Oct-14 2:32am    
thanks...
hello


C#
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;
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900