![]() ![]() | ||
As discussed in the In Depth section of this chapter, checked list boxes support checkboxes for each item. The CheckedListBox class is derived from the ListBox class like this (note that that means you can use the ListBox members we've already covered in this chapter in CheckListBox controls):
You can find the more notable public properties of the ListBox class in Table 7.4, the more notable methods in Table 7.5, and the more notable events in Table 7.6. Note that as with other Windows controls, I am not listing the notable properties, methods, and events ListBox inherits from the Control class, such as the Click event—you can see all that in Tables 5.1, 5.2, and 5.3 in Chapter 5.
Property |
Means |
---|---|
CheckedIndices |
Holds the collection of checked indices in this checked list box. |
CheckedItems |
Holds the collection of checked items in this checked list box. |
CheckOnClick |
Gets/sets if the checkbox should be toggled when the corresponding item is selected. |
ColumnWidth |
Gets/sets the width of columns; use this only in multicolumn checked list boxes. |
DisplayMember |
Indicates which property of object in the list box to show. If empty, the checked list box uses the object's ToString method instead. |
HorizontalScrollbar |
Gets/sets if a the checked list box should display a horizontal scroll bar. |
IntegralHeight |
Gets/sets a value specifying if the checked list box should automatically resize so it doesn't partial items. |
ItemHeight |
Returns the height of an item. |
Items |
Returns a collection of items in this checked list box. |
MultiColumn |
Gets/sets if the checked list box allows multiple columns. |
ScrollAlwaysVisible |
Gets/sets if the checked list box always shows a vertical scroll bar. |
SelectedIndex |
Gets/sets the index of the selected item in a checked list box. |
SelectedIndices |
Gets a collection that contains the zero-based indices of all currently selected items in the checked list box. |
SelectedItem |
Gets/sets the selected item in the checked list box. |
SelectedItems |
Gets a collection containing the selected items in the checked list box. |
SelectionMode |
Gets/sets the current selection mode. |
Sorted |
Gets/sets if the items in the checked list box should be sorted. The sort is alphabetical. |
Text |
Gets the text of the selected item in a checked list box. |
ThreeDCheckBoxes |
Gets/sets if the checkboxes are displayed Flat or Normal. |
TopIndex |
Gets/sets the index of the first item that is visible in the checked list box. |
Method |
Means |
---|---|
BeginUpdate |
Turns off visual updating of the list box until the EndUpdate method is called. |
ClearSelected |
Unselects all items in a checked list box. |
EndUpdate |
Resumes visual updating of the checked list box. |
FindString |
Finds the first item that begins with the indicated string in the checked list box. |
FindStringExact |
Finds the first item in the checked list box that matches the indicated string exactly. |
GetItemChecked |
Gets if the indicated item is checked or not. |
GetItemCheckState |
Gets the check state of the current item. |
GetItemHeight |
Gets the height of an item in the checked list box. |
GetItemText |
Gets an item's text. |
GetSelected |
Gets if the indicated item is selected. |
IndexFromPoint |
Returns the index of the item at the indicated coordinates. |
SetItemChecked |
Checks the item at the indicated index. |
SetItemCheckState |
Sets the indicated item's check state. |
SetSelected |
Selects or clears the selection for the indicated item in a checked list box. |
Event |
Means |
---|---|
ItemCheck |
Occurs when an item's checked state changes. |
SelectedIndexChanged |
Occurs when the SelectedIndex property has changed. |
Here's one property to note in particular— CheckOnClick. When you set this property to True, an item in a checked list box is checked or unchecked when you click it; otherwise, it takes a double-click. I'll set CheckOnClick to True for the CheckedListBoxes example in this chapter. (The default setting for this property is False.)
![]() ![]() | ||