Freigeben über


CheckedListBox.SelectionMode-Eigenschaft

Ruft einen Wert ab, der den Auswahlmodus angibt, oder legt diesen fest.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Overrides Property SelectionMode As SelectionMode
'Usage
Dim instance As CheckedListBox
Dim value As SelectionMode

value = instance.SelectionMode

instance.SelectionMode = value
public override SelectionMode SelectionMode { get; set; }
public:
virtual property SelectionMode SelectionMode {
    SelectionMode get () override;
    void set (SelectionMode value) override;
}
/** @property */
public SelectionMode get_SelectionMode ()

/** @property */
public void set_SelectionMode (SelectionMode value)
public override function get SelectionMode () : SelectionMode

public override function set SelectionMode (value : SelectionMode)

Eigenschaftenwert

Entweder der One-Wert oder None-Wert von System.Windows.Forms.SelectionMode.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentException

Es wurde versucht, einen Wert zuzuweisen, der kein System.Windows.Forms.SelectionMode mit dem Wert One oder None ist.

InvalidEnumArgumentException

Es wurde versucht, dem Steuerelement den MultiExtended-Wert von System.Windows.Forms.SelectionMode zuzuweisen.

Hinweise

Für CheckedListBox-Objekte wird keine Mehrfachauswahl unterstützt. Sie können den Modus auf ein Element oder kein Element festlegen.

Beispiel

Im folgenden Codebeispiel wird das Initialisieren eines CheckedListBox-Steuerelements durch Festlegen der CheckOnClick-Eigenschaft, der SelectionMode-Eigenschaft und der ThreeDCheckBoxes-Eigenschaft veranschaulicht. Im Beispiel wird die CheckedListBox mit Steuerelementen aufgefüllt und DisplayMember auf die Control.Name-Eigenschaft des Steuerelements festgelegt.

Zum Ausführen des Beispiels fügen Sie folgenden Code in ein Formular ein, das eine CheckedListBox mit dem Namen CheckedListBox1 enthält, und rufen Sie die InitializeCheckListBox-Methode im Konstruktor oder in der Load-Methode des Formulars auf.

// 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);
}
   // 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 = 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 );
   }

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

CheckedListBox-Klasse
CheckedListBox-Member
System.Windows.Forms-Namespace
SelectionMode