System.Windows.Forms.CheckedListBox Class

Displays a System.Windows.Forms.ListBox in which a check box is displayed to the left of each item.

See Also: CheckedListBox Members

Syntax

[System.ComponentModel.LookupBindingProperties]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
public class CheckedListBox : ListBox

Remarks

This control presents a list of items that the user can navigate by using the keyboard or the scrollbar on the right side of the control. The user can place a check mark by one or more items and the checked items can be navigated with the System.Windows.Forms.CheckedListBox.CheckedItemCollection and System.Windows.Forms.CheckedListBox.CheckedIndexCollection.

To add objects to the list at run time, assign an array of object references with the System.Windows.Forms.ListBox.ObjectCollection.AddRange(Object[]) method. The list then displays the default string value for each object. You can add individual items to the list with the System.Windows.Forms.CheckedListBox.ObjectCollection.Add(object, bool) method.

The System.Windows.Forms.CheckedListBox object supports three states through the System.Windows.Forms.CheckState enumeration: CheckState.Checked, CheckState.Indeterminate, and CheckState.Unchecked. You must set the state of CheckState.Indeterminate in the code because the user interface for a System.Windows.Forms.CheckedListBox does not provide a mechanism to do so.

If ListBox.UseTabStops is true, the System.Windows.Forms.CheckedListBox will recognize and expand tab characters in an item's text, creating columns. These tab stops are preset and cannot be changed. To use custom tab stops, set ListBox.UseTabStops to false, set ListBox.UseCustomTabOffsets to true, and add the custom values to the ListBox.CustomTabOffsets collection.

Note:

If the CheckedListBox.UseCompatibleTextRendering property is false, the ListBox.CustomTabOffsets property will be ignored and replaced with standard tab offsets.

The System.Windows.Forms.CheckedListBox class supports the following three indexed collections:

All items contained in the System.Windows.Forms.CheckedListBox control.

System.Windows.Forms.CheckedListBox.ObjectCollection

Checked items (including items in an indeterminate state), which is a subset of the items contained in the System.Windows.Forms.CheckedListBox control.

System.Windows.Forms.CheckedListBox.CheckedItemCollection

Checked indexes, which is a subset of the indexes into the items collection. These indexes specify items in a checked or indeterminate state.

System.Windows.Forms.CheckedListBox.CheckedIndexCollection

The following three tables are examples of the three indexed collections that the System.Windows.Forms.CheckedListBox class supports.

The first table provides an example of the indexed collection of items in the control (all items contained in the control).

0

Object 1

CheckState.Unchecked

1

Object 2

CheckState.Checked

2

Object 3

CheckState.Unchecked

3

Object 4

CheckState.Indeterminate

4

Object 5

CheckState.Checked

The second table provides an example of the indexed collection of the checked items.

0

Object 2

1

Object 4

2

Object 5

The third table provides an example of the indexed collection of indexes of checked items.

0

1

1

3

2

4

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0