radiobutton BeforeStateChange ?
-
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
-
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] }
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 -
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, 2007I 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] }
-
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
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
-
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] }
-
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
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
-
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
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
-
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
-
Yes, that's it, my fault was the calling of the base class even when it is disabled. tnx
-
Hi luc a disabled control should look different, but in a way I can decide of, and not in the way MS do. tnx
Standards are fantastic. Everyone should have one. :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }