Thursday, 10 March 2011

Three-state checkboxes in vb6

I still have (shame on me) to work with VB6. Visual Basic 6.0 standard checkboxes have three values, checked, unchecked, grayed out. The latter can be useful to cycle boolean fields between true, false and null values. Problem is, normally if you start with a grayed out checkbox, then comes the checked value, then the unchecked, and then ..the checked value again. To cycle between the three state, like a .NET Winforms checkbox with the threestate property set, use this Validate event


Private Sub chkMyCheckbox_Validate(Cancel As Boolean)
 If chkMyCheckbox.Value = 1 Then
   chkMyCheckbox.Value = 2
   Cancel = True
 End If
End Sub

Don't know why it works exactly, but it does...

No comments:

Post a Comment