Checkbox

How do you set the value/state of a checkbox without firing the Action event? I have tried .Value .SetBoolean() and .State but they all fire the Action event and therefore execute my code as if the user has clicked the button when the user has obviously not done so…

This is a tricky problem. The common solution is to set up a separate flag, a boolean property of the window, that you set if you you’re changing the checkbox’s state programmatically. Then in the action event of the checkbox, you only treat it as a “real” change if the flag is false. If it the flag is true, just skip the whole event. Just remember that after you set the flag, you change it back to false after you change the checkbox.

Xojo is a tricky problem! :slight_smile: Do you know if the Action event is guaranteed to fire as soon as the value/state changes (i.e. not on a separate thread or a later part of an event message processing loop)? So if I have pseudo code that looks like:

Property isLoadingFlag as boolean

SomeMethod()

isLoadingFlag = true
ckhbox.value = true

isLoadingFlag = false

Action()
if isLoadingFlag = false then
// handle the user event…
end

is this going to work for sure or could the Action() event fire after SomeMethod() completes?

Yes, what you’ve got should work. That’s just the way to do it.

When you call ckhbox.value = true it immediately fires the Action event of ckhbox, before it continues with the next line of code. (You can test this in the debugger, by stepping through the program and watch the code jump to the action event before returning to the original method and having the flag reset to false.)

Ok thanks Mark