다음을 통해 공유


ComboBox.ObjectCollection.AddRange(Object[]) 메서드

정의

에 대한 항목 목록에 항목 배열을 ComboBox추가합니다.

public:
 void AddRange(cli::array <System::Object ^> ^ items);
public:
 void AddRange(... cli::array <System::Object ^> ^ items);
public void AddRange(object[] items);
public void AddRange(params object[] items);
member this.AddRange : obj[] -> unit
Public Sub AddRange (items As Object())
Public Sub AddRange (ParamArray items As Object())

매개 변수

items
Object[]

목록에 추가할 개체의 배열입니다.

예외

매개 변수의 항목이 items .입니다 null.

예제

다음 코드 예제에서는 텍스트 속성을 설정 하 고 채우기 위해 메서드를 AddRange 사용 하 여 컨트롤을 초기화하는 ComboBox 방법을 보여 줍니다ComboBox. 또한 이벤트 처리를 보여 줍니다 DropDown . 예제를 실행하려면 폼에 다음 코드를 붙여넣고 폼의 생성자 또는 Load 메서드에서 메서드를 호출 InitializeComboBox 합니다.

internal:
   // Declare ComboBox1
   System::Windows::Forms::ComboBox^ ComboBox1;

private:
   // Initialize ComboBox1.
   void InitializeComboBox()
   {
      this->ComboBox1 = gcnew ComboBox;
      this->ComboBox1->Location = System::Drawing::Point( 128, 48 );
      this->ComboBox1->Name = "ComboBox1";
      this->ComboBox1->Size = System::Drawing::Size( 100, 21 );
      this->ComboBox1->TabIndex = 0;
      this->ComboBox1->Text = "Typical";
      array<String^>^ installs = {"Typical","Compact","Custom"};
      ComboBox1->Items->AddRange( installs );
      this->Controls->Add( this->ComboBox1 );
      
      // Hook up the event handler.
      this->ComboBox1->DropDown += gcnew System::EventHandler(
         this, &Form1::ComboBox1_DropDown );
   }

   // Handles the ComboBox1 DropDown event. If the user expands the  
   // drop-down box, a message box will appear, recommending the
   // typical installation.
   void ComboBox1_DropDown( Object^ sender, System::EventArgs^ e )
   {
      MessageBox::Show( "Typical installation is strongly recommended.",
         "Install information", MessageBoxButtons::OK,
         MessageBoxIcon::Information );
   }

// Declare ComboBox1.
internal System.Windows.Forms.ComboBox ComboBox1;

// Initialize ComboBox1.
private void InitializeComboBox()
{
    this.ComboBox1 = new ComboBox();
    this.ComboBox1.Location = new System.Drawing.Point(128, 48);
    this.ComboBox1.Name = "ComboBox1";
    this.ComboBox1.Size = new System.Drawing.Size(100, 21);
    this.ComboBox1.TabIndex = 0;
    this.ComboBox1.Text	= "Typical";
    string[] installs = new string[]{"Typical", "Compact", "Custom"};
    ComboBox1.Items.AddRange(installs);
    this.Controls.Add(this.ComboBox1);
    
    // Hook up the event handler.
    this.ComboBox1.DropDown +=  
        new System.EventHandler(ComboBox1_DropDown);
}

// Handles the ComboBox1 DropDown event. If the user expands the  
// drop-down box, a message box will appear, recommending the
// typical installation.
private void ComboBox1_DropDown(object sender, System.EventArgs e)
{
    MessageBox.Show("Typical installation is strongly recommended.", 
    "Install information", MessageBoxButtons.OK, 
        MessageBoxIcon.Information);
}

' Declare ComboBox1.
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox

' Initialize ComboBox1.
Private Sub InitializeComboBox()
    Me.ComboBox1 = New ComboBox
    Me.ComboBox1.Location = New System.Drawing.Point(128, 48)
    Me.ComboBox1.Name = "ComboBox1"
    Me.ComboBox1.Size = New System.Drawing.Size(100, 21)
    Me.ComboBox1.TabIndex = 0
    Me.ComboBox1.Text = "Typical"
    Dim installs() As String = New String() _
        {"Typical", "Compact", "Custom"}
    ComboBox1.Items.AddRange(installs)
    Me.Controls.Add(Me.ComboBox1)
End Sub

' Handles the ComboBox1 DropDown event. If the user expands the  
' drop-down box, a message box will appear, recommending the
' typical installation.
Private Sub ComboBox1_DropDown _ 
    (ByVal sender As Object, ByVal e As System.EventArgs) _ 
    Handles ComboBox1.DropDown
    MessageBox.Show("Typical installation is strongly recommended.", _
    "Install information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

설명

속성 ComboBoxSorted true로 설정되면 항목이 사전순으로 목록에 삽입됩니다. 그렇지 않으면 항목이 배열 내에서 발생하는 순서대로 삽입됩니다. 이 메서드는 일반적으로 개체 배열 String 을 전달하지만 모든 개체 형식의 배열을 이 메서드에 전달할 수 있습니다. 개체가 컬렉션에 추가되면 메서드는 개체의 ToString 메서드를 호출하여 목록에 표시할 문자열을 가져옵니다. 이 메서드를 사용하여 컬렉션에 항목을 추가하는 경우 성능을 최적화하기 위해 메서드 및 EndUpdate 메서드를 호출 BeginUpdate 할 필요가 없습니다.

적용 대상