CheckedListBox.ObjectCollection.Add 메서드

정의

CheckedListBox의 항목 목록에 항목을 추가합니다.

오버로드

Add(Object, Boolean)

항목을 CheckedListBox의 항목 목록에 추가하고, 추가할 개체와 개체의 선택 여부를 지정합니다.

Add(Object, CheckState)

항목을 CheckedListBox 항목 목록에 추가하고, 추가할 개체와 초기 선택 값을 지정합니다.

Add(Object, Boolean)

항목을 CheckedListBox의 항목 목록에 추가하고, 추가할 개체와 개체의 선택 여부를 지정합니다.

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

매개 변수

item
Object

컬렉션에 추가할 항목을 나타내는 개체입니다.

isChecked
Boolean

항목을 선택하면 true이고, 그렇지 않으면 false입니다.

반환

Int32

새로 추가한 항목의 인덱스입니다.

예제

다음 코드 예제에서는 초기화 하는 방법을 보여 줍니다는 CheckedListBox 설정 하 여 컨트롤을 CheckOnClick, SelectionMode, 및 ThreeDCheckBoxes 속성입니다. 예제 채웁니다를 CheckedListBox 집합과 컨트롤을 사용 하 여는 DisplayMemberControl.Name 컨트롤의 속성입니다.

예제를 실행 하려면 다음 코드를 포함 하는 폼의 붙여를 CheckedListBox CheckedListBox1 및 호출 합니다 InitializeCheckListBox 폼의 생성자에서 메서드 또는 Load 메서드.

   // 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

설명

이 메서드는 목록에 항목을 추가합니다. 목록 항목의 기존 목록 항목의 끝에 추가 됩니다. 정렬 된 선택된 목록 상자에 대 한 항목은 정렬된 된 위치에 따라 목록에 삽입 됩니다. SystemException 새 항목을 저장할 사용 가능한 공간이 부족 한 경우에 발생 합니다.

적용 대상

Add(Object, CheckState)

항목을 CheckedListBox 항목 목록에 추가하고, 추가할 개체와 초기 선택 값을 지정합니다.

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

매개 변수

item
Object

컬렉션에 추가할 항목을 나타내는 개체입니다.

check
CheckState

항목의 선택된 위치에 대한 초기 CheckState입니다.

반환

Int32

새로 추가한 항목의 인덱스입니다.

예외

check 매개 변수가 유효한 CheckState 값이 아닌 경우

설명

이 메서드는 선택된 목록 상자에 항목을 추가합니다. 정렬 되지 않은 검사 목록 상자에 대 한 항목은 기존 목록 항목의 끝에 추가 됩니다. 정렬 된 선택된 목록 상자에 대 한 항목은 정렬된 된 위치에 따라 목록에 삽입 됩니다. SystemException 새 항목을 저장할 사용 가능한 공간이 부족 한 경우에 발생 합니다.

적용 대상