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. radiobutton BeforeStateChange ?

radiobutton BeforeStateChange ?

Scheduled Pinned Locked Moved C#
question
14 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.
  • F fracalifa

    Hi all, depending on an access level of my app's I want to suppress a statechange of a radiobutton field (without disabling the controls). On a checkbox control I can override the onclick event and use the BeforeStateChange event. A radiobutton doesn't have such an event. Who has an idea to do that ? tnx Frank fracalifa

    R Offline
    R Offline
    ruanr
    wrote on last edited by
    #5

    A simple solution is to intercept checkchanged, and set the button back to checked if it is not checked. Not the most elegant though :)

    1 Reply Last reply
    0
    • L Luc Pattyn

      Hi, dont know about BeforeStateChange event, it is not in my MSDN documentation. Same MSDN documentation says one should not use RadioButton.OnClick for RadioButtons you can set AutoCheck=false and do all the Checked logic yourself. I consider it bad practice to change the behavior of a standard Control: a RadioButton (group) should either be enabled and you can operate it normally, or disabled and you cant operate it at all. For me there is no way in between. :)

      Luc Pattyn


      try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


      F Offline
      F Offline
      fracalifa
      wrote on last edited by
      #6

      Hi Luc, you are right, sorry, I override the onclick event and created an own event called checkBeforeChange like this protected override void OnClick(EventArgs e) { if(this.BeforeStateChange != null) { this.BeforeStateChange(this, ref cancelStateChg); } if(this.cancelStateChg) { this.Checked = !this.Checked; } base.OnClick (e); } this code is working on a checkbox, but not on a radiobutton. I would use enable=true/false but the bad is the color change to gray. If I could prevent the colorchange, everything would be fine. Frank -- modified at 6:37 Thursday 12th July, 2007

      L 1 Reply Last reply
      0
      • F fracalifa

        Hi Luc, you are right, sorry, I override the onclick event and created an own event called checkBeforeChange like this protected override void OnClick(EventArgs e) { if(this.BeforeStateChange != null) { this.BeforeStateChange(this, ref cancelStateChg); } if(this.cancelStateChg) { this.Checked = !this.Checked; } base.OnClick (e); } this code is working on a checkbox, but not on a radiobutton. I would use enable=true/false but the bad is the color change to gray. If I could prevent the colorchange, everything would be fine. Frank -- modified at 6:37 Thursday 12th July, 2007

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #7

        I understand that, but the basic point is a Control that is disabled MUST look different; if it did not, the user would manipulate it unknowingly, and then complain it does not work as expected. :)

        Luc Pattyn


        try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


        F 1 Reply Last reply
        0
        • F fracalifa

          Hi all, depending on an access level of my app's I want to suppress a statechange of a radiobutton field (without disabling the controls). On a checkbox control I can override the onclick event and use the BeforeStateChange event. A radiobutton doesn't have such an event. Who has an idea to do that ? tnx Frank fracalifa

          M Offline
          M Offline
          Martin 0
          wrote on last edited by
          #8

          Hello,

          fracalifa wrote per e-mail:

          Hi Martin, tnx, that works, but how can I prevent the statechange of the radiobutton ? Is there a cancel option which I can use for? Tnx Frank [confused]

          I haven't even found "statechange", is it .NET>1.1? P.S.: please respond in the forum, cause I'm not answering per e-mail!

          All the best, Martin

          F 1 Reply Last reply
          0
          • L Luc Pattyn

            I understand that, but the basic point is a Control that is disabled MUST look different; if it did not, the user would manipulate it unknowingly, and then complain it does not work as expected. :)

            Luc Pattyn


            try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


            F Offline
            F Offline
            fracalifa
            wrote on last edited by
            #9

            Hi luc a disabled control should look different, but in a way I can decide of, and not in the way MS do. tnx

            L 1 Reply Last reply
            0
            • M Martin 0

              Hello,

              fracalifa wrote per e-mail:

              Hi Martin, tnx, that works, but how can I prevent the statechange of the radiobutton ? Is there a cancel option which I can use for? Tnx Frank [confused]

              I haven't even found "statechange", is it .NET>1.1? P.S.: please respond in the forum, cause I'm not answering per e-mail!

              All the best, Martin

              F Offline
              F Offline
              fracalifa
              wrote on last edited by
              #10

              Hi Martin, other than a checkbox a radiobutton is a group of controls. With the checkbox I can do suppressing the toggle of the state, with the radiobutton(s) I can do not.My wish is to prevent the change of state from uncheched to checked when clicking on it, that's all (without enable = false). tnx Frank

              M 1 Reply Last reply
              0
              • F fracalifa

                Hi Martin, other than a checkbox a radiobutton is a group of controls. With the checkbox I can do suppressing the toggle of the state, with the radiobutton(s) I can do not.My wish is to prevent the change of state from uncheched to checked when clicking on it, that's all (without enable = false). tnx Frank

                M Offline
                M Offline
                Martin 0
                wrote on last edited by
                #11

                But haven't you allready told the solution with overriding the OnClick. I tested it with an inherited (from RadioButton) control.

                	private bool \_disable = false;
                	public bool Disable
                	{
                		get
                		{
                			return \_disable;
                		}
                		set
                		{
                			if(value!=\_disable)
                			{
                				\_disable = value;
                			}
                		}
                	}
                
                	protected override void OnClick(EventArgs e)
                	{
                		if(!Disable)
                			base.OnClick (e);
                	}
                

                Works well for me.

                All the best, Martin

                F 1 Reply Last reply
                0
                • M Martin 0

                  But haven't you allready told the solution with overriding the OnClick. I tested it with an inherited (from RadioButton) control.

                  	private bool \_disable = false;
                  	public bool Disable
                  	{
                  		get
                  		{
                  			return \_disable;
                  		}
                  		set
                  		{
                  			if(value!=\_disable)
                  			{
                  				\_disable = value;
                  			}
                  		}
                  	}
                  
                  	protected override void OnClick(EventArgs e)
                  	{
                  		if(!Disable)
                  			base.OnClick (e);
                  	}
                  

                  Works well for me.

                  All the best, Martin

                  F Offline
                  F Offline
                  fracalifa
                  wrote on last edited by
                  #12

                  Yes, that's it, my fault was the calling of the base class even when it is disabled. tnx

                  M 1 Reply Last reply
                  0
                  • F fracalifa

                    Yes, that's it, my fault was the calling of the base class even when it is disabled. tnx

                    M Offline
                    M Offline
                    Martin 0
                    wrote on last edited by
                    #13

                    Glad I could help! You are wellcome!

                    All the best, Martin

                    1 Reply Last reply
                    0
                    • F fracalifa

                      Hi luc a disabled control should look different, but in a way I can decide of, and not in the way MS do. tnx

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #14

                      Standards are fantastic. Everyone should have one. :)

                      Luc Pattyn


                      try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


                      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