Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Apr 29, 2002



Full Text Search: The Key to Better Natural Language Queries for NoSQL in Node.js

Force Tri-State Checkbox Cycling

The CheckBox control in VB supports three positions: Checked, Unchecked, and Grayed. Unfortunately, the default behavior for the control is to cycle between Checked and Unchecked. To set it to Grayed, you must do it programatically. This code shows you how to cycle between the three positions (the order is Checked->Unchecked->Grayed->Checked ...):
Private Sub Check1_Click()
Static iState As CheckBoxConstants
Static bUserClick As Boolean
' Trap if the user clicked on the control
' or if the event was fired because you
' changed the value below
bUserClick = (iState <> Check1.Value)
' Prevents you from entering an infinite
' loop and getting an Out of Stack Space error
If bUserClick Then
Select Case iState
Case vbChecked
iState = vbUnchecked
Case vbUnchecked
iState = vbGrayed
Case vbGrayed
iState = vbChecked
End Select
' This will raise another click event but
' your boolean check prevents you from looping
Check1.Value = iState
End If
End Sub
Eric Litwin
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date