Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CheckedListBox.SelectionMode Property

Gets or sets a value specifying the selection mode.

[Visual Basic]
Overrides Public Property SelectionMode As SelectionMode
[C#]
public override SelectionMode SelectionMode {get; set;}
[C++]
public: __property SelectionMode get_SelectionMode();
public: __property void set_SelectionMode(SelectionMode);
[JScript]
public override function get SelectionMode() : SelectionMode;
public override function set SelectionMode(SelectionMode);

Property Value

Either SelectionMode.One or SelectionMode.None.

Exceptions

Exception Type Condition
ArgumentException An attempt was made to assign a value that is not SelectionMode.One or SelectionMode.None.

Remarks

For CheckedListBox objects, multiple selection is not supported. You can set the mode to one item or no items.

Example

[Visual Basic, C#] The following code example demonstrates initializing a CheckedListBox control by setting the CheckOnClick, SelectionMode, and CheckedListBox. System.Windows.Forms.CheckedListBox.3DCheckBoxes properties. The example populates the CheckedListBox with controls and sets the CheckedListBox. System.Windows.Forms.CheckedListBox.Display member to the name property of the control. 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.

[Visual Basic] 
' 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.
Friend WithEvents CheckedListBox1 As System.Windows.Forms.CheckedListBox

Private Sub InitializeCheckedListBox()
    Me.CheckedListBox1 = New CheckedListBox
    Me.CheckedListBox1.Location = New System.Drawing.Point(40, 90)
    Me.CheckedListBox1.CheckOnClick = True
    Me.CheckedListBox1.Name = "CheckedListBox1"
    Me.CheckedListBox1.Size = New System.Drawing.Size(120, 94)
    Me.CheckedListBox1.TabIndex = 1
    Me.CheckedListBox1.SelectionMode = SelectionMode.One
    Me.CheckedListBox1.ThreeDCheckBoxes = True

    Dim aControl As Control
    For Each aControl In Me.Controls
        Me.CheckedListBox1.Items.Add(aControl, False)
    Next

    Me.CheckedListBox1.DisplayMember = "Name"
    Me.CheckedListBox1.Items.Add(CheckedListBox1)
    Me.Controls.Add(Me.CheckedListBox1)
End Sub

[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);
}

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

CheckedListBox Class | CheckedListBox Members | System.Windows.Forms Namespace | SelectionMode

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.