JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating Three-State Checkboxes

In VB6 and before, you could set any checkbox to one of three states—now you need to set the checkbox's ThreeState property to True to indicate that you want it to support three states.

By default, checkboxes are two-state controls; you use the Checked property to get or set the value of a two-state checkbox. However, if you set the checkbox's ThreeState property to True, you make the checkbox into a three-state control.

You use the CheckState property to get or set the value of the three-state checkbox. The three states are:

  • Checked— A check appears in the checkbox.

  • Unchecked— No check appears in the checkbox.

  • Indeterminate— A check appears in the checkbox on a gray background.

There's a discussion of these three states in the In Depth section of this chapter. You can see a checkbox in the indeterminate state in Figure 6.13.


Figure 6.13: A checkbox in the indeterminate state.
Tip 

If the ThreeState property is set to True, the Checked property will return True for either a checked or indeterminate state.

If you've set the checkbox's ThreeState property to True, you can set its CheckState property to CheckState.Indeterminate at design time or run time to set the checkbox to the indeterminate state:

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    TextBox1.Text = "You clicked checkbox 1"
    CheckBox1.CheckState = CheckState.Indeterminate
End Sub
Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor