Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to uncheck a (radio button) on the 2nd click. (e.g. I click once, it puts a check mark - I click a second time, it removes it).
Posted

This would be abuse of well-known and expected UI behavior. As Keyur Satyadev correctly put it, it's a check box behavior (already available).

(Even is somebody required something like that, your responsibility is to deny it, explain why it should be done -- communicate and regulate the situation. Such things happen.)
 
Share this answer
 
v2
Hi
you can use check box for same. why you want to use radio button for same. is there any specific requirement then please let us know here.
 
Share this answer
 
I will suggest you to use Checkbox control where you can actually do what you have asked.
But radio button is only that you want to use refer following code :


bool blnState;

public Form1()
{
    InitializeComponent();
}

private void radioButton1_MouseDown(object sender, MouseEventArgs e)
{
    blnState = radioButton1.Checked;
}

private void radioButton1_MouseUp(object sender, MouseEventArgs e)
{
    radioButton1.Checked = !blnState;
}


where radioButton1 is the name of the radio button that you are using.
I have used the mousedown and mouseup events of this control.
 
Share this answer
 
Comments
Yusuf 25-Jan-11 11:25am    
First off, this is not the way to do. There is a checkbox which basically works the way the OP wants.

Second, you are handling MouseDown and MouseUp. A click fires both. Since you are the action, it nothing will change. You need to handle what you doing on the click event.

BUT DON"T DO IT!
Pravin Patil, Mumbai 26-Jan-11 2:53am    
Hi Yusuf, Please read my first line.

I will suggest you to use Checkbox control where you can actually do what you have asked.
But radio button is only that you want to use refer following code :

I suggested to use Checkbox only, but you can do this using radio button also. And secondly this code works fine, Do test it. You can not handle it on click event.

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