How to: Radiobutton check event confirmation ???
-
Hi! Does anyone knows how can I show a messagebox, after a user tries to change a radiobutton, and cancel that action if needed? I already tried to do it inside several events, but without success. I would like to do something like this:
private void radioButton_TMP_Validating(object sender, CancelEventArgs e) { if (MessageBox.Show("Are you sure?", "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { e.Cancel; } }
I appreciate if someone could help me with this. I didn't find any solution when "gOOgling" :( Thanks!!! -
Hi! Does anyone knows how can I show a messagebox, after a user tries to change a radiobutton, and cancel that action if needed? I already tried to do it inside several events, but without success. I would like to do something like this:
private void radioButton_TMP_Validating(object sender, CancelEventArgs e) { if (MessageBox.Show("Are you sure?", "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { e.Cancel; } }
I appreciate if someone could help me with this. I didn't find any solution when "gOOgling" :( Thanks!!!try this :
if (MessageBox.Show("Are you sure?", "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
radioButton.Checked = false;
else
radioButton.Checked = true;and do not put this code in Validating event, Click event will be good for it hope this will help
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
try this :
if (MessageBox.Show("Are you sure?", "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
radioButton.Checked = false;
else
radioButton.Checked = true;and do not put this code in Validating event, Click event will be good for it hope this will help
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y -------------------------------------------------------- 128 bit encrypted signature, crack if you can
Thanks for the post Xmen! Although, I don't think that this is the right way to do this. First because using the click event, the radiobutton on that time is already changed and, like this, I will need to rollback that action, unchecking that radiobutton and checking the previous one. What I really want is to have the chance to cancel and prevent the radionbutton to be checked. This must be done before the radiobutton is checked. And by the way, using the click event is not enough because the radiobuttons can be check using the keyboard. There must be a simple and efficient way to do this. :) Any ideas?
-
Thanks for the post Xmen! Although, I don't think that this is the right way to do this. First because using the click event, the radiobutton on that time is already changed and, like this, I will need to rollback that action, unchecking that radiobutton and checking the previous one. What I really want is to have the chance to cancel and prevent the radionbutton to be checked. This must be done before the radiobutton is checked. And by the way, using the click event is not enough because the radiobuttons can be check using the keyboard. There must be a simple and efficient way to do this. :) Any ideas?
hmm... i think only CheckedChanged event can help but it may cause of iteration, but you can use some logic of bool or you should make a custom event.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
Thanks for the post Xmen! Although, I don't think that this is the right way to do this. First because using the click event, the radiobutton on that time is already changed and, like this, I will need to rollback that action, unchecking that radiobutton and checking the previous one. What I really want is to have the chance to cancel and prevent the radionbutton to be checked. This must be done before the radiobutton is checked. And by the way, using the click event is not enough because the radiobuttons can be check using the keyboard. There must be a simple and efficient way to do this. :) Any ideas?
-
you could use the CheckedChanged event which is called when the checked property is changed, so that should work for the key board as well as the mouse. hope that helps
-
Hi! Does anyone knows how can I show a messagebox, after a user tries to change a radiobutton, and cancel that action if needed? I already tried to do it inside several events, but without success. I would like to do something like this:
private void radioButton_TMP_Validating(object sender, CancelEventArgs e) { if (MessageBox.Show("Are you sure?", "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { e.Cancel; } }
I appreciate if someone could help me with this. I didn't find any solution when "gOOgling" :( Thanks!!! -
EventArgs e
ofCheckedChanged
event dont haveCancel
propertyTVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
That's true jasper018. But even like this, the CheckedChanged event is called only after the radio button is checked. I still need to rollback that action if needed. There must be an event that is called right before the radiobutton is checked.
I know there is a AutoCheck propery, the default is set to true, and what that does it when a raido button is checked, it clears all the other raido buttons in the group... I have never used it, but it might be help full, but then you would have to clear the the raido buttons manually on user confirmation...
-
Thanks for help bicphuong! I understand your idea but in CheckedChange event, using "EventArgs e" I will not have the possibility to use the "Cancel" property. Until now, I only found that property when using the Validating event, and the behavior was not so far way from what I want. Anyway, what happened was that sometimes he reacts like I was expecting, but sometimes not. Seems that this event occurs lately.
-
I know there is a AutoCheck propery, the default is set to true, and what that does it when a raido button is checked, it clears all the other raido buttons in the group... I have never used it, but it might be help full, but then you would have to clear the the raido buttons manually on user confirmation...
-
I know there is a AutoCheck propery, the default is set to true, and what that does it when a raido button is checked, it clears all the other raido buttons in the group... I have never used it, but it might be help full, but then you would have to clear the the raido buttons manually on user confirmation...
Thank you all! Finally a solution. :-D I will post the code here for future people with the same problem. Like jasper suggest before, i did set the AutoCheck property to false on all radiobuttons (4 in my case) and add just 1 event on all of them (the Click event). It works when the user click the radiobutton or even when using the keyboard. Perfectly as it seems to me, and not so hard coded anyway.
private void radioButton_tipo_Click(object sender, EventArgs e) { if (((RadioButton)sender).Checked == true) { return; } else if (MessageBox.Show("Are you sure?", "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ((RadioButton)sender).Checked = true; if (sender.Equals(radioButton_tipo_SA)) { radioButton_tipo_SQ.Checked = false; radioButton_tipo_ACE.Checked = false; radioButton_tipo_SQU.Checked = false; } else if (((RadioButton)sender) == radioButton_tipo_SQ) { radioButton_tipo_SA.Checked = false; radioButton_tipo_ACE.Checked = false; radioButton_tipo_SQU.Checked = false; } else if (((RadioButton)sender) == radioButton_tipo_ACE) { radioButton_tipo_SQ.Checked = false; radioButton_tipo_SA.Checked = false; radioButton_tipo_SQU.Checked = false; } else { radioButton_tipo_SQ.Checked = false; radioButton_tipo_ACE.Checked = false; radioButton_tipo_SA.Checked = false; } } }
Thanks everybody for the help !!!