Cancel CheckedChanged event?
Posted on 2004-09-07
I have an interesting problem that I'm not sure has an elegant solution.
I have a Win form with a bunch of controls. One of them is a checkbox. When the user checks or unchecks the checkbox, the CheckedChanged event is fired. That event has some code which does certain things.
What I'd like is when the user clicks the checkbox to check or uncheck it, there is a condition I want to check first and based on that, it'll either check or uncheck the control.
Right now, when the control is checked, the event is fired and the checked property is changed and then it runs the code to check the condition and based on that, I might have to programmatically reverse back to the previous checked property. And when I reverse it, the CheckedChanged property is called again (and again and again). The workaround for this is ugly.
Is there an elegant solution for this?