ListView.Items ListView.Items ListView.Items ListView.Items Property

정의

컨트롤에 있는 모든 항목이 포함된 컬렉션을 가져옵니다.Gets a collection containing all items in the control.

public:
 property System::Windows::Forms::ListView::ListViewItemCollection ^ Items { System::Windows::Forms::ListView::ListViewItemCollection ^ get(); };
public System.Windows.Forms.ListView.ListViewItemCollection Items { get; }
member this.Items : System.Windows.Forms.ListView.ListViewItemCollection
Public ReadOnly Property Items As ListView.ListViewItemCollection

속성 값

예제

다음 코드 예제를 ListView 3 개를 사용 하 여 컨트롤 ListViewItem 지정 된 개체 및 3 ListViewItem.ListViewSubItem 각 항목에 대해 지정 된 개체입니다.The following code example creates a ListView control with three ListViewItem objects specified and three ListViewItem.ListViewSubItem objects specified for each item. 예제에서는 ColumnHeader 하위 항목 세부 정보 보기에 표시할 개체입니다.The example also creates ColumnHeader objects to display the subitems in details view. 두 개의 ImageList 이미지를 제공 하 여 코드 예제의 만들어집니다 개체는 ListViewItem 개체입니다.Two ImageList objects are also created in the code example to provide images for the ListViewItem objects. 이러한 ImageList 개체에 추가 되는 LargeImageListSmallImageList 속성입니다.These ImageList objects are added to the LargeImageList and SmallImageList properties. 이 예제에서는 만들기에서 다음 속성을 사용 합니다 ListView 제어 합니다.The example uses the following properties in creating the ListView control.

이 예제 코드를 추가 하려면를 Form 폼에서 다른 메서드나 생성자의 예제에서 만든 메서드를 호출 합니다.This example requires that you have added the code to a Form and call the method created in the example from the constructor or another method on the form. 이 예제에서는 명명 된 이미지도 필요 MySmallImage1, MySmallImage2MyLargeImage1, 및 MyLargeImage2 C 드라이브의 루트 디렉터리에 있는The example also requires that images named MySmallImage1, MySmallImage2, MyLargeImage1, and MyLargeImage2 are located in the root directory of drive 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 'CreateMyListView

설명

사용 하는 ListView.ListViewItemCollection 이 속성에 의해 반환 항목, 항목을 제거을 추가한 항목의 수를 가져옵니다.Using the ListView.ListViewItemCollection returned by this property, you can add items, remove items, and obtain a count of items. 컬렉션의 항목을 사용 하 여 수행할 수 있는 작업에 대 한 자세한 내용은 참조는 ListView.ListViewItemCollection 클래스 참조 항목입니다.For more information on the tasks that can be performed with the items in the collection, see the ListView.ListViewItemCollection class reference topics.

적용 대상

추가 정보