JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Checking or Unchecking Items in Checked List Boxes from Code

You can use a checked list box's SetItemChecked method to check or uncheck items in a checked list box by passing a value of True or False, respectively. Here's an example from the CheckedListBoxes example on the CD-ROM where I'm unchecking item 0 in the checked list box:

Private Sub Button3_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button3.Click
    CheckedListBox1.SetItemChecked(0, False)
End Sub

You can see the results in Figure 7.11; in this case, I've clicked the "Uncheck item" button, which has removed the check mark in the checked list box in front of item 0.


Figure 7.11: Unchecking an item in a checked list box.

You also can use the SetItemCheckState method to work with three-state checkboxes; you pass this method the index of the item to change and a value from the CheckState enumeration:

  • Checked— The control is checked.

  • Indeterminate— The control is indeterminate. An indeterminate control generally has a shaded appearance.

  • Unchecked— The control is unchecked.

Here's an example: CheckedListBox1.SetItemCheckState(0, CheckState.Unchecked).

Related solution:

Found on page:

Creating Three-State Checkboxes

275

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor