Partager via


CheckedListBox.ObjectCollection.Add Méthode

Définition

Ajoute un élément à la liste des éléments d’un CheckedListBox.

Surcharges

Nom Description
Add(Object, Boolean)

Ajoute un élément à la liste des éléments d’un CheckedListBox, en spécifiant l’objet à ajouter et s’il est vérifié.

Add(Object, CheckState)

Ajoute un élément à la liste des éléments d’un CheckedListBox, en spécifiant l’objet à ajouter et la valeur initiale vérifiée.

Add(Object, Boolean)

Source:
CheckedListBox.ObjectCollection.cs
Source:
CheckedListBox.ObjectCollection.cs
Source:
CheckedListBox.ObjectCollection.cs
Source:
CheckedListBox.ObjectCollection.cs
Source:
CheckedListBox.ObjectCollection.cs

Ajoute un élément à la liste des éléments d’un CheckedListBox, en spécifiant l’objet à ajouter et s’il est vérifié.

public:
 int Add(System::Object ^ item, bool isChecked);
public int Add(object item, bool isChecked);
override this.Add : obj * bool -> int
Public Function Add (item As Object, isChecked As Boolean) As Integer

Paramètres

item
Object

Objet représentant l’élément à ajouter à la collection.

isChecked
Boolean

true pour vérifier l’élément ; sinon, false.

Retours

Index de l’élément nouvellement ajouté.

Exemples

L’exemple de code suivant illustre l’initialisation d’un CheckedListBox contrôle en définissant les propriétés et ThreeDCheckBoxes les CheckOnClickSelectionModepropriétés. L’exemple remplit les CheckedListBox contrôles et définit la DisplayMemberControl.Name propriété du contrôle.

Pour exécuter l’exemple, collez le code suivant dans un formulaire contenant un CheckedListBox contrôle CheckedListBox1 nommé et appelez la InitializeCheckListBox méthode à partir du constructeur ou Load de la méthode du formulaire.

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

Remarques

Cette méthode ajoute un élément à la liste. Pour une liste, l’élément est ajouté à la fin de la liste existante d’éléments. Pour une zone de liste triée cochée, l’élément est inséré dans la liste en fonction de sa position triée. Un SystemException événement se produit s’il n’y a pas suffisamment d’espace disponible pour stocker le nouvel élément.

S’applique à

Add(Object, CheckState)

Source:
CheckedListBox.ObjectCollection.cs
Source:
CheckedListBox.ObjectCollection.cs
Source:
CheckedListBox.ObjectCollection.cs
Source:
CheckedListBox.ObjectCollection.cs
Source:
CheckedListBox.ObjectCollection.cs

Ajoute un élément à la liste des éléments d’un CheckedListBox, en spécifiant l’objet à ajouter et la valeur initiale vérifiée.

public:
 int Add(System::Object ^ item, System::Windows::Forms::CheckState check);
public int Add(object item, System.Windows.Forms.CheckState check);
override this.Add : obj * System.Windows.Forms.CheckState -> int
Public Function Add (item As Object, check As CheckState) As Integer

Paramètres

item
Object

Objet représentant l’élément à ajouter à la collection.

check
CheckState

Initial CheckState pour la partie vérifiée de l’élément.

Retours

Index de l’élément nouvellement ajouté.

Exceptions

Le check paramètre n’est pas l’une des valeurs valides CheckState .

Remarques

Cette méthode ajoute un élément à la zone de liste cochée. Pour une zone de liste non triée, l’élément est ajouté à la fin de la liste existante d’éléments. Pour une zone de liste triée cochée, l’élément est inséré dans la liste en fonction de sa position triée. Un SystemException événement se produit s’il n’y a pas suffisamment d’espace disponible pour stocker le nouvel élément.

S’applique à