Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to: Radiobutton check event confirmation ???

How to: Radiobutton check event confirmation ???

Scheduled Pinned Locked Moved C#
questionhelptutorial
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Xmen Real

    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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y -------------------------------------------------------- 128 bit encrypted signature, crack if you can

    B Offline
    B Offline
    biscoito
    wrote on last edited by
    #3

    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?

    X J 2 Replies Last reply
    0
    • B biscoito

      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?

      X Offline
      X Offline
      Xmen Real
      wrote on last edited by
      #4

      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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y -------------------------------------------------------- 128 bit encrypted signature, crack if you can

      1 Reply Last reply
      0
      • B biscoito

        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?

        J Offline
        J Offline
        jasper018
        wrote on last edited by
        #5

        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

        B 1 Reply Last reply
        0
        • J jasper018

          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

          B Offline
          B Offline
          biscoito
          wrote on last edited by
          #6

          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.

          J 1 Reply Last reply
          0
          • B biscoito

            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!!!

            B Offline
            B Offline
            bicphuong
            wrote on last edited by
            #7

            [Message Deleted]

            X B 2 Replies Last reply
            0
            • B bicphuong

              [Message Deleted]

              X Offline
              X Offline
              Xmen Real
              wrote on last edited by
              #8

              EventArgs e of CheckedChanged event dont have Cancel property

              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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y -------------------------------------------------------- 128 bit encrypted signature, crack if you can

              1 Reply Last reply
              0
              • B biscoito

                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.

                J Offline
                J Offline
                jasper018
                wrote on last edited by
                #9

                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...

                B 2 Replies Last reply
                0
                • B bicphuong

                  [Message Deleted]

                  B Offline
                  B Offline
                  biscoito
                  wrote on last edited by
                  #10

                  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.

                  1 Reply Last reply
                  0
                  • J jasper018

                    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...

                    B Offline
                    B Offline
                    biscoito
                    wrote on last edited by
                    #11

                    It's a very hard coded idea but, until now, the only one that might work (i think) :) I will give a try, at least until i can't find a better and efficient way to do this (because there must be a simple way). Thanks!

                    1 Reply Last reply
                    0
                    • J jasper018

                      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...

                      B Offline
                      B Offline
                      biscoito
                      wrote on last edited by
                      #12

                      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 !!!

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups