ListView.ListViewItemCollection 클래스

정의

ListView 컨트롤에 있거나 ListViewGroup에 할당된 항목의 컬렉션을 나타냅니다.

public: ref class ListView::ListViewItemCollection : System::Collections::IList
public class ListView.ListViewItemCollection : System.Collections.IList
[System.ComponentModel.ListBindable(false)]
public class ListView.ListViewItemCollection : System.Collections.IList
type ListView.ListViewItemCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
[<System.ComponentModel.ListBindable(false)>]
type ListView.ListViewItemCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
Public Class ListView.ListViewItemCollection
Implements IList
상속
ListView.ListViewItemCollection
특성
구현

예제

다음 코드 예제에서는 에 항목을 추가하는 방법을 보여 줍니다 ListView.ListViewItemCollection. 의 ListView1 속성은 Items 형식ListView.ListViewItemCollection입니다. 이 예제를 실행하려면 다음 코드를 라는 개체와 라는 ListView1TextBox1개체가 포함된 ListView 양식에 TextBox 붙여넣습니다. 폼의 InitializeListView 생성자 또는 Load 이벤트 처리기에서 메서드를 호출합니다.

// This method adds two columns to the ListView, setting the Text 
// and TextAlign, and Width properties of each ColumnHeader.  The 
// HeaderStyle property is set to NonClickable since the ColumnClick 
// event is not handled.  Finally the method adds ListViewItems and 
// SubItems to each column.
void InitializeListView()
{
   this->ListView1 = gcnew System::Windows::Forms::ListView;
   this->ListView1->BackColor = System::Drawing::SystemColors::Control;
   this->ListView1->Dock = System::Windows::Forms::DockStyle::Top;
   this->ListView1->Location = System::Drawing::Point( 0, 0 );
   this->ListView1->Name = "ListView1";
   this->ListView1->Size = System::Drawing::Size( 292, 130 );
   this->ListView1->TabIndex = 0;
   this->ListView1->View = System::Windows::Forms::View::Details;
   this->ListView1->MultiSelect = true;
   this->ListView1->HideSelection = false;
   this->ListView1->HeaderStyle = ColumnHeaderStyle::Nonclickable;
   ColumnHeader^ columnHeader1 = gcnew ColumnHeader;
   columnHeader1->Text = "Breakfast Item";
   columnHeader1->TextAlign = HorizontalAlignment::Left;
   columnHeader1->Width = 146;
   ColumnHeader^ columnHeader2 = gcnew ColumnHeader;
   columnHeader2->Text = "Price Each";
   columnHeader2->TextAlign = HorizontalAlignment::Center;
   columnHeader2->Width = 142;
   this->ListView1->Columns->Add( columnHeader1 );
   this->ListView1->Columns->Add( columnHeader2 );
   array<String^>^foodList = {"Juice","Coffee","Cereal & Milk","Fruit Plate","Toast & Jelly","Bagel & Cream Cheese"};
   array<String^>^foodPrice = {"1.09","1.09","2.19","2.49","1.49","1.49"};
   for ( int count = 0; count < foodList->Length; count++ )
   {
      ListViewItem^ listItem = gcnew ListViewItem( foodList[ count ] );
      listItem->SubItems->Add( foodPrice[ count ] );
      ListView1->Items->Add( listItem );

   }
   this->Controls->Add( ListView1 );
}
  // This method adds two columns to the ListView, setting the Text 
  // and TextAlign, and Width properties of each ColumnHeader.  The 
  // HeaderStyle property is set to NonClickable since the ColumnClick 
  // event is not handled.  Finally the method adds ListViewItems and 
  // SubItems to each column.
  private void InitializeListView()
  {
      this.ListView1 = new System.Windows.Forms.ListView();
      this.ListView1.BackColor = System.Drawing.SystemColors.Control;
      this.ListView1.Dock = System.Windows.Forms.DockStyle.Top;
      this.ListView1.Location = new System.Drawing.Point(0, 0);
      this.ListView1.Name = "ListView1";
      this.ListView1.Size = new System.Drawing.Size(292, 130);
      this.ListView1.TabIndex = 0;
      this.ListView1.View = System.Windows.Forms.View.Details;
      this.ListView1.MultiSelect = true;
      this.ListView1.HideSelection = false;
      this.ListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
      
      ColumnHeader columnHeader1 = new ColumnHeader();
      columnHeader1.Text = "Breakfast Item";
      columnHeader1.TextAlign = HorizontalAlignment.Left;
      columnHeader1.Width = 146;

      ColumnHeader columnHeader2 = new ColumnHeader();
      columnHeader2.Text = "Price Each";
      columnHeader2.TextAlign = HorizontalAlignment.Center;
      columnHeader2.Width = 142;

      this.ListView1.Columns.Add(columnHeader1);
      this.ListView1.Columns.Add(columnHeader2);

      string[] foodList = new string[]{"Juice", "Coffee", 
          "Cereal & Milk", "Fruit Plate", "Toast & Jelly", 
          "Bagel & Cream Cheese"};
      string[] foodPrice = new string[]{"1.09", "1.09", "2.19", 
          "2.49", "1.49", "1.49"};
      
      for(int count=0; count < foodList.Length; count++)
      {
          ListViewItem listItem = new ListViewItem(foodList[count]);
          listItem.SubItems.Add(foodPrice[count]);
          ListView1.Items.Add(listItem);
      }
      this.Controls.Add(ListView1);
  }
' This method adds two columns to the ListView, setting the Text 
' and TextAlign, and Width properties of each ColumnHeader.  The 
' HeaderStyle property is set to NonClickable since the ColumnClick 
' event is not handled.  Finally the method adds ListViewItems and 
' SubItems to each column.
Private Sub InitializeListView()
    Me.ListView1 = New System.Windows.Forms.ListView
    Me.ListView1.BackColor = System.Drawing.SystemColors.Control
    Me.ListView1.Dock = System.Windows.Forms.DockStyle.Top
    Me.ListView1.Location = New System.Drawing.Point(0, 0)
    Me.ListView1.Name = "ListView1"
    Me.ListView1.Size = New System.Drawing.Size(292, 130)
    Me.ListView1.TabIndex = 0
    Me.ListView1.View = System.Windows.Forms.View.Details
    Me.ListView1.MultiSelect = True
    Me.ListView1.HideSelection = False
    ListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable
    Dim columnHeader1 As New ColumnHeader
    With columnHeader1
        .Text = "Breakfast Item"
        .TextAlign = HorizontalAlignment.Left
        .Width = 146
    End With
    Dim columnHeader2 As New ColumnHeader
    With columnHeader2
        .Text = "Price Each"
        .TextAlign = HorizontalAlignment.Center
        .Width = 142
    End With

    Me.ListView1.Columns.Add(columnHeader1)
    Me.ListView1.Columns.Add(columnHeader2)
    Dim foodList() As String = New String() {"Juice", "Coffee", _
        "Cereal & Milk", "Fruit Plate", "Toast & Jelly", _
        "Bagel & Cream Cheese"}
    Dim foodPrice() As String = New String() {"1.09", "1.09", _
        "2.19", "2.49", "1.49", "1.49"}
    Dim count As Integer
    For count = 0 To foodList.Length - 1
        Dim listItem As New ListViewItem(foodList(count))
        listItem.SubItems.Add(foodPrice(count))
        ListView1.Items.Add(listItem)
    Next
    Me.Controls.Add(Me.ListView1)
End Sub

설명

ListView.ListViewItemCollection 컨트롤에 표시되거나 에 ListView 할당된 항목을 저장합니다 ListViewGroup. 컨트롤 내에서 선택된 항목을 확인할 수 있도록 클래스 내에 ListView 정의된 두 개의 다른 컬렉션이 ListView 있습니다. 클래스는 ListView.SelectedListViewItemCollection 컨트롤에서 선택된 항목을 결정하기 위한 속성과 메서드를 ListView 제공하는 반면ListView.SelectedIndexCollection, 클래스를 사용하면 컨트롤 내에서 ListView 선택된 인덱스를 ListView.ListViewItemCollection 확인할 수 있습니다. 선택 컬렉션 클래스 외에도 이 컬렉션 내에서 확인되는 항목(컨트롤의 ListView 속성이 로 설정된 경우CheckBoxes)을 true확인할 수 있는 두 가지 클래스가 있습니다.

컬렉션에 항목을 추가하는 방법에는 여러 가지가 있습니다. 메서드는 Add 컬렉션에 단일 항목을 추가합니다. 컬렉션에 여러 항목을 추가하려면 항목 배열을 만들고 메서드에 AddRange 전달합니다. 컬렉션의 특정 위치에 항목을 삽입하려는 경우 메서드를 Insert 사용할 수 있습니다. 항목을 제거하려면 컬렉션에 항목이 Remove 있는 위치를 알고 있는 경우 메서드 또는 RemoveAt 메서드를 사용할 수 있습니다. 메서드 Clear 를 사용하면 메서드를 사용하여 Remove 한 번에 단일 항목을 제거하는 대신 컬렉션에서 모든 항목을 제거할 수 있습니다.

항목 추가 및 제거 ListView.ListViewItemCollection 를 위한 메서드 및 속성 외에도 는 컬렉션에서 항목을 찾는 메서드를 제공합니다. Contains 메서드를 사용하면 항목이 컬렉션의 멤버인지 여부를 확인할 수 있습니다. 항목이 컬렉션에 있다는 것을 알게 되면 메서드를 IndexOf 사용하여 항목이 컬렉션에 있는 위치를 확인할 수 있습니다.

생성자

ListView.ListViewItemCollection(ListView)

ListView.ListViewItemCollection 클래스의 새 인스턴스를 초기화합니다.

속성

Count

컬렉션의 항목 수를 가져옵니다.

IsReadOnly

컬렉션이 읽기 전용인지를 나타내는 값을 가져옵니다.

Item[Int32]

컬렉션 내의 지정된 인덱스에 있는 항목을 가져오거나 설정합니다.

Item[String]

지정된 키를 가진 항목을 검색합니다.

메서드

Add(ListViewItem)

기존 ListViewItem을 컬렉션에 추가합니다.

Add(String)

지정된 텍스트를 사용하여 항목을 만든 다음 컬렉션에 추가합니다.

Add(String, Int32)

지정된 텍스트와 이미지를 사용하여 항목을 만든 다음 컬렉션에 추가합니다.

Add(String, String)

지정된 텍스트와 이미지를 사용하여 항목을 만든 다음 컬렉션에 추가합니다.

Add(String, String, Int32)

지정된 키, 텍스트 및 이미지를 사용하여 항목을 만든 다음 컬렉션에 추가합니다.

Add(String, String, String)

지정된 키, 텍스트 및 이미지를 사용하여 항목을 만든 다음 컬렉션에 추가합니다.

AddRange(ListView+ListViewItemCollection)

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

AddRange(ListViewItem[])

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

Clear()

컬렉션에서 모든 항목을 제거합니다.

Contains(ListViewItem)

지정된 항목이 컬렉션에 있는지 여부를 확인합니다.

ContainsKey(String)

컬렉션에 지정된 키를 가진 항목이 포함되어 있는지 여부를 확인합니다.

CopyTo(Array, Int32)

배열 내의 지정된 위치에서 기존 배열로 전체 컬렉션을 복사합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
Find(String, Boolean)

지정된 키와 이름이 일치하는 항목을 검색합니다. 선택적으로 하위 항목을 검색할 수 있습니다.

GetEnumerator()

항목 컬렉션을 반복하는 데 사용할 열거자를 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IndexOf(ListViewItem)

지정된 항목의 컬렉션 내에 있는 인덱스를 반환합니다.

IndexOfKey(String)

지정된 키를 가진 항목의 인덱스를 검색합니다.

Insert(Int32, ListViewItem)

기존 ListViewItem을 컬렉션의 지정한 인덱스에 삽입합니다.

Insert(Int32, String)

새 항목을 만들어 컬렉션의 지정한 인덱스에 삽입합니다.

Insert(Int32, String, Int32)

지정한 이미지 인덱스를 사용하여 새 항목을 만들고 컬렉션의 지정한 인덱스에 삽입합니다.

Insert(Int32, String, String)

지정된 텍스트와 이미지를 사용하여 새 항목을 만든 다음 컬렉션의 지정된 인덱스에 삽입합니다.

Insert(Int32, String, String, Int32)

지정된 키, 텍스트 및 이미지를 사용하여 새 항목을 만든 다음 컬렉션의 지정된 인덱스에 삽입합니다.

Insert(Int32, String, String, String)

지정된 키, 텍스트 및 이미지를 사용하여 새 항목을 만든 다음 컬렉션의 지정된 인덱스에 추가합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Remove(ListViewItem)

컬렉션에서 지정한 항목을 제거합니다.

RemoveAt(Int32)

컬렉션 내의 지정된 인덱스에 있는 항목을 제거합니다.

RemoveByKey(String)

지정된 키를 가진 항목을 컬렉션에서 제거합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.IsSynchronized

해당 컬렉션에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지를 나타내는 값을 가져옵니다.

ICollection.SyncRoot

컨트롤 컬렉션에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

IList.Add(Object)

컬렉션에 기존 개체를 추가합니다.

IList.Contains(Object)

지정한 항목이 컬렉션에 있는지를 확인합니다.

IList.IndexOf(Object)

지정된 항목의 컬렉션 내에 있는 인덱스를 반환합니다.

IList.Insert(Int32, Object)

컬렉션의 지정된 인덱스에 개체를 삽입합니다.

IList.IsFixedSize

컬렉션의 크기가 고정되어 있는지를 나타내는 값을 가져옵니다.

IList.Item[Int32]

컬렉션 내의 지정된 인덱스에 있는 ListViewItem을 가져오거나 설정합니다.

IList.Remove(Object)

컬렉션에서 지정한 항목을 제거합니다.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

추가 정보