ListView.ListViewItemCollection.AddRange 메서드

정의

항목의 배열을 컬렉션에 추가합니다.

오버로드

AddRange(ListView+ListViewItemCollection)

항목의 컬렉션을 컬렉션에 추가합니다.

AddRange(ListViewItem[])

컬렉션에 ListViewItem 개체 배열을 추가합니다.

AddRange(ListView+ListViewItemCollection)

항목의 컬렉션을 컬렉션에 추가합니다.

public:
 void AddRange(System::Windows::Forms::ListView::ListViewItemCollection ^ items);
public void AddRange (System.Windows.Forms.ListView.ListViewItemCollection items);
member this.AddRange : System.Windows.Forms.ListView.ListViewItemCollection -> unit
Public Sub AddRange (items As ListView.ListViewItemCollection)

매개 변수

items
ListView.ListViewItemCollection

컬렉션에 추가할 ListView.ListViewItemCollection입니다.

예외

items이(가) null인 경우

포함하는 ListView가 가상 모드에 있는 경우

설명

포함하는 ListView 항목이 정렬된 AddRange 경우 메서드는 정렬된 순서로 항목을 추가합니다. 그렇지 않으면 컬렉션의 끝에 항목을 추가합니다.

적용 대상

AddRange(ListViewItem[])

컬렉션에 ListViewItem 개체 배열을 추가합니다.

public:
 void AddRange(cli::array <System::Windows::Forms::ListViewItem ^> ^ values);
public:
 void AddRange(cli::array <System::Windows::Forms::ListViewItem ^> ^ items);
public void AddRange (System.Windows.Forms.ListViewItem[] values);
public void AddRange (System.Windows.Forms.ListViewItem[] items);
member this.AddRange : System.Windows.Forms.ListViewItem[] -> unit
member this.AddRange : System.Windows.Forms.ListViewItem[] -> unit
Public Sub AddRange (values As ListViewItem())
Public Sub AddRange (items As ListViewItem())

매개 변수

valuesitems
ListViewItem[]

컬렉션에 추가할 ListViewItem 개체의 배열입니다.

예외

items이(가) null인 경우

예제

다음 예제에서는 개체 3개 ListViewItem 와 각 항목에 대해 세 개의 ListViewItem.ListViewSubItem 개체가 지정된 컨트롤을 만듭니다ListView. 예제에서는 ColumnHeader 하위 항목 세부 정보 보기에 표시할 개체입니다. 두 개의 ImageList 이미지를 제공 하 여 코드 예제의 만들어집니다 개체는 ListViewItem 개체입니다. 이러한 ImageList 개체에 추가 되는 LargeImageListSmallImageList 속성입니다. 이 예제에서는 만들기에서 다음 속성을 사용 합니다 ListView 제어:

이 예제에서는 코드를 a Form 에 추가하고 폼의 생성자 또는 다른 메서드에서 예제에서 만든 메서드를 호출해야 합니다. 이 예제에서는 명명 된 이미지도 필요 MySmallImage1, MySmallImage2MyLargeImage1, 및 MyLargeImage2 C 드라이브의 루트 디렉터리에 있는

private:
   void CreateMyListView()
   {
      // Create a new ListView control.
      ListView^ listView1 = gcnew ListView;
      listView1->Bounds = Rectangle(Point(10,10),System::Drawing::Size( 300, 200 ));

      // Set the view to show details.
      listView1->View = View::Details;

      // Allow the user to edit item text.
      listView1->LabelEdit = true;

      // Allow the user to rearrange columns.
      listView1->AllowColumnReorder = true;

      // Display check boxes.
      listView1->CheckBoxes = true;

      // Select the item and subitems when selection is made.
      listView1->FullRowSelect = true;

      // Display grid lines.
      listView1->GridLines = true;

      // Sort the items in the list in ascending order.
      listView1->Sorting = SortOrder::Ascending;

      // Create three items and three sets of subitems for each item.
      ListViewItem^ item1 = gcnew ListViewItem( "item1",0 );

      // Place a check mark next to the item.
      item1->Checked = true;
      item1->SubItems->Add( "1" );
      item1->SubItems->Add( "2" );
      item1->SubItems->Add( "3" );
      ListViewItem^ item2 = gcnew ListViewItem( "item2",1 );
      item2->SubItems->Add( "4" );
      item2->SubItems->Add( "5" );
      item2->SubItems->Add( "6" );
      ListViewItem^ item3 = gcnew ListViewItem( "item3",0 );

      // Place a check mark next to the item.
      item3->Checked = true;
      item3->SubItems->Add( "7" );
      item3->SubItems->Add( "8" );
      item3->SubItems->Add( "9" );

      // Create columns for the items and subitems.
      // Width of -2 indicates auto-size.
      listView1->Columns->Add( "Item Column", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 2", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 3", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 4", -2, HorizontalAlignment::Center );

      //Add the items to the ListView.
      array<ListViewItem^>^temp1 = {item1,item2,item3};
      listView1->Items->AddRange( temp1 );

      // Create two ImageList objects.
      ImageList^ imageListSmall = gcnew ImageList;
      ImageList^ imageListLarge = gcnew ImageList;

      // Initialize the ImageList objects with bitmaps.
      imageListSmall->Images->Add( Bitmap::FromFile( "C:\\MySmallImage1.bmp" ) );
      imageListSmall->Images->Add( Bitmap::FromFile( "C:\\MySmallImage2.bmp" ) );
      imageListLarge->Images->Add( Bitmap::FromFile( "C:\\MyLargeImage1.bmp" ) );
      imageListLarge->Images->Add( Bitmap::FromFile( "C:\\MyLargeImage2.bmp" ) );

      //Assign the ImageList objects to the ListView.
      listView1->LargeImageList = imageListLarge;
      listView1->SmallImageList = imageListSmall;
      
      // Add the ListView to the control collection.
      this->Controls->Add( listView1 );
   }
private void CreateMyListView()
{
    // Create a new ListView control.
    ListView listView1 = new ListView();
    listView1.Bounds = new Rectangle(new Point(10,10), new Size(300,200));

    // Set the view to show details.
    listView1.View = View.Details;
    // Allow the user to edit item text.
    listView1.LabelEdit = true;
    // Allow the user to rearrange columns.
    listView1.AllowColumnReorder = true;
    // Display check boxes.
    listView1.CheckBoxes = true;
    // Select the item and subitems when selection is made.
    listView1.FullRowSelect = true;
    // Display grid lines.
    listView1.GridLines = true;
    // Sort the items in the list in ascending order.
    listView1.Sorting = SortOrder.Ascending;
                
    // Create three items and three sets of subitems for each item.
    ListViewItem item1 = new ListViewItem("item1",0);
    // Place a check mark next to the item.
    item1.Checked = true;
    item1.SubItems.Add("1");
    item1.SubItems.Add("2");
    item1.SubItems.Add("3");
    ListViewItem item2 = new ListViewItem("item2",1);
    item2.SubItems.Add("4");
    item2.SubItems.Add("5");
    item2.SubItems.Add("6");
    ListViewItem item3 = new ListViewItem("item3",0);
    // Place a check mark next to the item.
    item3.Checked = true;
    item3.SubItems.Add("7");
    item3.SubItems.Add("8");
    item3.SubItems.Add("9");

    // Create columns for the items and subitems.
    // Width of -2 indicates auto-size.
    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center);

    //Add the items to the ListView.
    listView1.Items.AddRange(new ListViewItem[]{item1,item2,item3});

    // Create two ImageList objects.
    ImageList imageListSmall = new ImageList();
    ImageList imageListLarge = new ImageList();

    // Initialize the ImageList objects with bitmaps.
    imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage1.bmp"));
    imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage2.bmp"));
    imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage1.bmp"));
    imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage2.bmp"));

    //Assign the ImageList objects to the ListView.
    listView1.LargeImageList = imageListLarge;
    listView1.SmallImageList = imageListSmall;

    // Add the ListView to the control collection.
    this.Controls.Add(listView1);
}
Private Sub CreateMyListView()
    ' Create a new ListView control.
    Dim listView1 As New ListView()
    listView1.Bounds = New Rectangle(New Point(10, 10), New Size(300, 200))

    ' Set the view to show details.
    listView1.View = View.Details
    ' Allow the user to edit item text.
    listView1.LabelEdit = True
    ' Allow the user to rearrange columns.
    listView1.AllowColumnReorder = True
    ' Display check boxes.
    listView1.CheckBoxes = True
    ' Select the item and subitems when selection is made.
    listView1.FullRowSelect = True
    ' Display grid lines.
    listView1.GridLines = True
    ' Sort the items in the list in ascending order.
    listView1.Sorting = SortOrder.Ascending

    ' Create three items and three sets of subitems for each item.
    Dim item1 As New ListViewItem("item1", 0)
    ' Place a check mark next to the item.
    item1.Checked = True
    item1.SubItems.Add("1")
    item1.SubItems.Add("2")
    item1.SubItems.Add("3")
    Dim item2 As New ListViewItem("item2", 1)
    item2.SubItems.Add("4")
    item2.SubItems.Add("5")
    item2.SubItems.Add("6")
    Dim item3 As New ListViewItem("item3", 0)
    ' Place a check mark next to the item.
    item3.Checked = True
    item3.SubItems.Add("7")
    item3.SubItems.Add("8")
    item3.SubItems.Add("9")

    ' Create columns for the items and subitems.
    ' Width of -2 indicates auto-size.
    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

    'Add the items to the ListView.
    listView1.Items.AddRange(New ListViewItem() {item1, item2, item3})

    ' Create two ImageList objects.
    Dim imageListSmall As New ImageList()
    Dim imageListLarge As New ImageList()

    ' Initialize the ImageList objects with bitmaps.
    imageListSmall.Images.Add(Bitmap.FromFile("C:\MySmallImage1.bmp"))
    imageListSmall.Images.Add(Bitmap.FromFile("C:\MySmallImage2.bmp"))
    imageListLarge.Images.Add(Bitmap.FromFile("C:\MyLargeImage1.bmp"))
    imageListLarge.Images.Add(Bitmap.FromFile("C:\MyLargeImage2.bmp"))

    'Assign the ImageList objects to the ListView.
    listView1.LargeImageList = imageListLarge
    listView1.SmallImageList = imageListSmall

    ' Add the ListView to the control collection.
    Me.Controls.Add(listView1)
End Sub

설명

이 메서드를 사용하여 다른 ListView 컨트롤의 항목을 다시 사용할 수 있습니다. 단일 추가 하려는 경우 ListViewItem를 사용 하 여를 Add 메서드. 사용할 수도 있습니다는 Insert 메서드는 단일 추가 하려는 경우 ListViewItem 컬렉션의 특정 위치에 있습니다.

이 메서드를 사용하여 여러 ListViewItem 개체를 에 할당할 수도 있습니다 ListViewGroup.

속성이 ListView.Sorting 다른 SortOrder.None 값으로 설정되거나 속성이 ListViewItemSorter 설정된 경우 항목이 추가된 후 목록이 정렬됩니다. 그렇지 않으면 항목이 목록의 끝에 삽입됩니다. 목록이 정렬되지 않은 경우 메서드를 Insert 사용하여 특정 위치에 항목을 ListView 삽입할 수 있습니다.

추가 정보

적용 대상