I only see three event handlers for checkboxes: changed, gets focus, lost focus.
I have 16 checkboxes, I am trying to change their ticked/unticked status programmatically. I need to have the same number of boxes ticked all the time, so when a user changes the status of one, I need to change the status of another one. If I use the "changed" event handler, it is also triggered for the other box, which I do not want. I was hoping that the "lost focus" handler would work for me, but it does not. It is not triggered when a user taps on the checkbox (and releases it). I read the reason for this in other threads and I can understand this.
I can do some workaround, but I thought I ask first about a "tapped on" like event handler for checkboxes. Is there none like this or I just did not find it?
No, it is not random. I will change the first one on the list which needs to be changed after the one the user changed. The goal is to have a selection which the user chooses.
As I said, I can sort this out with a bit of coding, but I am surprised that there is no event handler like this.
A simple case with two checkboxes when exactly one needs to be checked can easily lead to an infinite loop if I use the "changed" handler to change the state of the other (and do nothing else).
Let's call the checkboxes c1, c2, ... c16. If all of these are checked, it is a separate situation.
In other cases if for example c5 is checked, then I start to check the status of c6, c7, ...c16, c1, c2, ..., c4 and change the status of the first one that brings back the same total. I did not think this through completely, but I think, this way the user can pick their desired selection in a way that later selections don't undo what they did before. I am not sure about this, though. Maybe I will need a different algorithm.
I have encountered these cascading checkbox changed events in the past.
They are very befuddling.
I would avoid them by switching to Buttons with ON/OFF text or varying background colors.
You get the Click event once, but changing multiple button texts does not trigger events.
Yes, indeed, buttons can work. I was trying to do it with checkbox, because this is what their purpose is. I will find a workaround. I know that my next question is not helpful, but is there a reason why checkboxes only have these three event handlers?
However, I just thought of a way to debounce checkboxes, in the same way you would debounce electrical contacts by adding capacitance.
Bring in a Clock component to your project, if you don't have one yet.
Init a global variable LastCheckBoxFlipMS, initially 0.
Init a global FLIP_MINIMUM_MS constant = 30 (my estimate)
When Any Checkbox Changed,
If (Clock1.SystemTime - global LastCheckBoxFlipMS) > global FLIP_MINIMUM_MS then
treat this as a manually initiated checkbox flip
set global LastCheckBoxFlipMS to Clock1.SystemTime
else
ignore the flip
Thanks. I am not sure I will try this. I think I will go in a different direction and simply let the users choose whatever they want and keep a warning message displayed if the number of checkboxes do not match the number needed.
I have another method "in trial", which is to remove the last Changed checkbox from the list of checkboxes supplied to the AnyCheckBox Changed event, and then handle the remaining checkboxes in a separate list. As ABG says, befuddling...