Check/uncheck a checkbox

I have tried everything i found in the docs and forum but i can’t get a checkbox to check/uncheck itself through code. Basically it takes a value from my-msql (0 or 1) and then checks the box if needed. I had no problem doing this in .Net or php, but xojo is picking on me. All the other code works (pulling data) just need the checkbox to work ugggg.

If you can show us what you tried I’m sure someone will help you. Either post the specific code that you think is giving you problems or share a demo using dropbox or other service.

CheckBox1.Value = 0 doesn’t work either, but CheckBox1.Value = False does. I tried something like Checkbox1.VisiableStates and everything else that i found. The doc for Checkbox Value doesn’t tell you how to set it, just how to read it. It is a very basic feature, something i never had issues with using other languages. Thats why i was banging my head on the desk lol.

Correct uses:

Checkbox1.Value = True
' Or
Checkbox1.VisualState = Checkbox.VisualStates.Checked
' Or
Checkbox1.Value = False
' Or
Checkbox1.VisualState = Checkbox.VisualStates.Unchecked
' Or
Checkbox1.VisualState = Checkbox.VisualStates.Indeterminate

Basically it takes a value from my-msql (0 or 1)

you cound use extend to convert your integer.
put this methods in a module as global scope.

Public Function GetCheck(Extends ck as CheckBox) as Integer

  If ck.Value = True Then
    Return 1
  Elseif ck.Value = False Then
    Return 0
  End If
End Function

Public Sub SetCheck(Extends ck as CheckBox, value as Integer)

  If value = 0 Then
    ck.Value = False
  Elseif value = 1 Then
    ck.Value = True
    Var e As New InvalidArgumentException // subclass of RuntimeException
    e.Message = "Invalid Argument, the value must be 0 or 1"
    Raise e
  End If
End Sub

example to use

CheckBox1.SetCheck 1
System.DebugLog CheckBox1.GetCheck.ToString
1 Like

For another simpler solution…

Checkbox1.Value = (rec.column("name").integervalue = 1)