CheckedListBox.SelectionMode Property

Definition

Gets or sets a value specifying the selection mode.

C#
public override System.Windows.Forms.SelectionMode SelectionMode { get; set; }

Property Value

Either the One or None value of SelectionMode.

Exceptions

An attempt was made to assign a value that is not a SelectionMode value of One or None.

An attempt was made to assign the MultiExtended value of SelectionMode to the control.

Examples

The following code example demonstrates initializing a CheckedListBox control by setting the SelectionMode to allow one item in the list to be selected.

To run the example, paste the following code in a form containing a CheckedListBox named CheckedListBox1 and call the InitializeCheckListBox method from the form's constructor or Load method.

C#
// This method initializes CheckedListBox1 with a list of all 
// the controls on the form. It sets the selection mode
// to single selection and allows selection with a single click.
// It adds itself to the list before adding itself to the form.

internal System.Windows.Forms.CheckedListBox CheckedListBox1;

private void InitializeCheckedListBox()
{
    this.CheckedListBox1 = new CheckedListBox();
    this.CheckedListBox1.Location = new System.Drawing.Point(40, 90);
    this.CheckedListBox1.CheckOnClick = true;
    this.CheckedListBox1.Name = "CheckedListBox1";
    this.CheckedListBox1.Size = new System.Drawing.Size(120, 94);
    this.CheckedListBox1.TabIndex = 1;
    this.CheckedListBox1.SelectionMode = SelectionMode.One;
    this.CheckedListBox1.ThreeDCheckBoxes = true;

    foreach ( Control aControl in this.Controls )
    {
        this.CheckedListBox1.Items.Add(aControl, false);
    }

    this.CheckedListBox1.DisplayMember = "Name";
    this.CheckedListBox1.Items.Add(CheckedListBox1);
    this.Controls.Add(this.CheckedListBox1);
}

Remarks

The SelectionMode property determines whether one item in the list box can be selected or no items can be selected. For CheckedListBox objects, multiple selection is not supported. You can set the mode to one item or no items.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also