CheckedListBox::SelectionMode Property


Gets or sets a value specifying the selection mode.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

property SelectionMode SelectionMode {
	virtual SelectionMode get() override;
	virtual void set(SelectionMode value) override;

Property Value

Type: System.Windows.Forms::SelectionMode

Either the One or None value of System.Windows.Forms::SelectionMode.

Exception Condition

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


An attempt was made to assign the MultiExtended value of System.Windows.Forms::SelectionMode to the control.

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.

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.

   // 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.
   System::Windows::Forms::CheckedListBox^ CheckedListBox1;

   void InitializeCheckedListBox()
      this->CheckedListBox1 = gcnew CheckedListBox;
      this->CheckedListBox1->Location = System::Drawing::Point( 40, 90 );
      this->CheckedListBox1->CheckOnClick = true;
      this->CheckedListBox1->Name = "CheckedListBox1";
      this->CheckedListBox1->Size = System::Drawing::Size( 120, 94 );
      this->CheckedListBox1->TabIndex = 1;
      this->CheckedListBox1->SelectionMode = SelectionMode::One;
      this->CheckedListBox1->ThreeDCheckBoxes = true;
      System::Collections::IEnumerator^ myEnum = this->Controls->GetEnumerator();
      while ( myEnum->MoveNext() )
         Control^ aControl = safe_cast<Control^>(myEnum->Current);
         this->CheckedListBox1->Items->Add( aControl, false );

      this->CheckedListBox1->DisplayMember = "Name";
      this->CheckedListBox1->Items->Add( CheckedListBox1 );
      this->Controls->Add( this->CheckedListBox1 );

.NET Framework
Available since 1.1
Return to top