Checkbox not responding to mouse click

I have encountered a strange problem with a Checkbox on a desktop app. I built this app for both Windows and Mac platforms. The Windows version works perfectly. The Mac version, however, will not allow the checkbox to change its state when clicked (yes - it is enabled!).

I have narrowed the problem down to a line of code in the window’s Paint event, which sets the checkbox state in accordance with a database field.
ie, like this:-
If rsSet.Field(“Set0”).StringValue = “0” then
chkTestAddress.State = Checkbox.CheckedStates.UnChecked
chkTestAddress.State = Checkbox.CheckedStates.Checked
End If

If I comment out the above code, then the checkbox functions normally on MacOS. Why??

I appreciate that setting the checkbox state does fire the checkbox’s .Action event, but that event would simply re-write the database field… Aahhhh! I wonder, maybe this is a circular file lock problem?? But why does the same app work fine on MS Windows?

Any thoughts?

My thought is that putting that code in the .paint event is probably causing the problem. I would suspect a tight loop of paint - touch the UI - fire the paint - touch the UI - etc.

Yes… never update the UI in the Paint Event… as you have no control over when it will happen (yes you can force it with INVALIDATE/REFRESH, but it will occur on its own when the app needs to insure a clean display)

You should set/reset UI elements when the underlying data changes (ie… when you do a MOVENEXT etc in the recordset)

I had similar problems when setting controls in code and wanting to prevent Action / Change events from running. I suppose everyone has their own way of doing that. What I do is define a window property INITIALISING AS BOOLEAN.
To set the control I code
Initialising = true
Checkbox1.value = true // The action event will run.
Initialising = false

The first line of code in the action event reads
If initialising then return

Might help someone.