ListView.SelectedListViewItemCollection ListView.SelectedListViewItemCollection ListView.SelectedListViewItemCollection ListView.SelectedListViewItemCollection Class


list view 컨트롤에서 선택된 항목의 컬렉션을 나타냅니다.Represents the collection of selected items in a list view control.

public: ref class ListView::SelectedListViewItemCollection : System::Collections::IList
public class ListView.SelectedListViewItemCollection : System.Collections.IList
type ListView.SelectedListViewItemCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
Public Class ListView.SelectedListViewItemCollection
Implements IList


다음 코드 예제는 SelectedItems, SelectedIndexChanged 이벤트 및 HeaderStyle 멤버 및 ListView.SelectedListViewItemCollection 클래스.The following code example demonstrates using the SelectedItems, SelectedIndexChanged event, and HeaderStyle members and the ListView.SelectedListViewItemCollection class. 이 예제를 실행 하려면 포함 된 폼에서 다음 코드를 붙여 넣습니다를 ListView 개체인 ListView1TextBox 라는 TextBox1합니다.To run this example, paste the following code in a form that contains a ListView object named ListView1 and a TextBox named TextBox1. 호출 된 InitializeListView 폼의 생성자에서 메서드 또는 Load 이벤트 처리기입니다.Call the InitializeListView method from the form's constructor or the Load event handler. 이 예제에서는 이벤트 처리기와 올바르게 연결 된 SelectedIndexChanged 이벤트This example requires that the event handler is correctly associated with the SelectedIndexChanged event

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

	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]);

' 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

    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))
End Sub
// Uses the SelectedItems property to retrieve and tally the price 
// of the selected menu items.
void ListView1_SelectedIndexChanged_UsingItems( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   ListView::SelectedListViewItemCollection^ breakfast = this->ListView1->SelectedItems;
   double price = 0.0;
   System::Collections::IEnumerator^ myEnum = breakfast->GetEnumerator();
   while ( myEnum->MoveNext() )
      ListViewItem^ item = safe_cast<ListViewItem^>(myEnum->Current);
      price += Double::Parse( item->SubItems[ 1 ]->Text );

   // Output the price to TextBox1.
   TextBox1->Text = price.ToString();
// Uses the SelectedItems property to retrieve and tally the price 
// of the selected menu items.
private void ListView1_SelectedIndexChanged_UsingItems(
	object sender, System.EventArgs e)

	ListView.SelectedListViewItemCollection breakfast = 
	double price = 0.0;
	foreach ( ListViewItem item in breakfast )
		price += Double.Parse(item.SubItems[1].Text);

	// Output the price to TextBox1.
	TextBox1.Text = price.ToString();
' Uses the SelectedItems property to retrieve and tally the price 
' of the selected menu items.
Private Sub ListView1_SelectedIndexChanged_UsingItems _
    (ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles ListView1.SelectedIndexChanged

    Dim breakfast As ListView.SelectedListViewItemCollection = _
    Dim item As ListViewItem
    Dim price As Double = 0.0
    For Each item In breakfast
        price += Double.Parse(item.SubItems(1).Text)

    ' Output the price to TextBox1.
    TextBox1.Text = CType(price, String)
End Sub


A ListView.SelectedListViewItemCollection 에서 선택한 항목 저장을 ListView 제어 합니다.A ListView.SelectedListViewItemCollection stores the selected items in a ListView control. 항목에 저장 합니다 ListView.SelectedListViewItemCollection 에 포함 된 항목을 ListView.ListViewItemCollection입니다.The items stored in the ListView.SelectedListViewItemCollection are items contained in the ListView.ListViewItemCollection. 합니다 ListView.ListViewItemCollection 에 표시 된 모든 항목을 저장 합니다 ListView합니다.The ListView.ListViewItemCollection stores all items displayed in the ListView.

다음 표에서 방법의 예를 보여 줍니다 ListView.ListViewItemCollection 항목을 저장 합니다 ListView 예에서 선택 상태와 ListView 컨트롤입니다.The following table shows an example of how the ListView.ListViewItemCollection stores the items of the ListView as well as their selection states in an example ListView control.

인덱스Index 항목Item ListView의 선택 상태Selection state in the ListView
00 Item1Item1 선택 취소Unselected
11 Item2Item2 선택함Selected
22 Item3Item3 선택 취소Unselected
33 Item4Item4 선택함Selected
44 Item5Item5 선택함Selected

기반으로 합니다 ListView.ListViewItemCollection 이전 테이블의 예제에서는 다음 표에 나와 방법을 ListView.SelectedListViewItemCollection 표시 됩니다.Based on the ListView.ListViewItemCollection example in the previous table, the following table demonstrates how the ListView.SelectedListViewItemCollection would appear.

인덱스Index ListViewItemCollection에서 선택한 항목Selected item in the ListViewItemCollection
00 Item2Item2
11 Item4Item4
22 Item5Item5

다양 한 컬렉션을 사용 하 여 작업을 수행 하려면이 클래스의 메서드와 속성을 사용할 수 있습니다.You can use the properties and methods of this class to perform a variety of tasks with the collection. Contains 메서드를 사용 하면 항목에서 지 여부를 결정 합니다 ListView.ListViewItemCollection 클래스의 멤버인는 ListView.SelectedListViewItemCollection합니다.The Contains method enables you to determine whether an item from the ListView.ListViewItemCollection class is a member of the ListView.SelectedListViewItemCollection. 항목이 컬렉션에 있는지를 알고 나면 사용할 수 있습니다 합니다 IndexOf 에 있는 항목의 위치를 결정 하는 방법의 ListView.SelectedListViewItemCollection합니다.Once you know that the item is in the collection, you can use the IndexOf method to determine the position of the item in the ListView.SelectedListViewItemCollection.


ListView.SelectedListViewItemCollection(ListView) ListView.SelectedListViewItemCollection(ListView) ListView.SelectedListViewItemCollection(ListView) ListView.SelectedListViewItemCollection(ListView)

ListView.SelectedListViewItemCollection 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the ListView.SelectedListViewItemCollection class.


Count Count Count Count

컬렉션의 항목 수를 가져옵니다.Gets the number of items in the collection.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

컬렉션이 읽기 전용인지를 나타내는 값을 가져옵니다.Gets a value indicating whether the collection is read-only.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

컬렉션 내의 지정된 인덱스에 위치하는 항목을 가져옵니다.Gets the item at the specified index within the collection.

Item[String] Item[String] Item[String] Item[String]

컬렉션에서 지정된 키를 가진 항목을 가져옵니다.Gets an item with the specified key from the collection.


Clear() Clear() Clear() Clear()

컬렉션에서 모든 항목을 제거합니다.Removes all items from the collection.

Contains(ListViewItem) Contains(ListViewItem) Contains(ListViewItem) Contains(ListViewItem)

지정된 항목이 컬렉션에 있는지 여부를 확인합니다.Determines whether the specified item is located in the collection.

ContainsKey(String) ContainsKey(String) ContainsKey(String) ContainsKey(String)

지정된 키를 가진 항목이 컬렉션에 포함되어 있는지 여부를 확인합니다.Determines whether an item with the specified key is contained in the collection.

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

배열 내의 지정된 위치에서 기존 배열로 전체 컬렉션을 복사합니다.Copies the entire collection into an existing array at a specified location within the array.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

선택된 항목 컬렉션 전체를 반복하는 데 사용할 수 있는 열거자를 반환합니다.Returns an enumerator that can be used to iterate through the selected item collection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(Inherited from Object)
IndexOf(ListViewItem) IndexOf(ListViewItem) IndexOf(ListViewItem) IndexOf(ListViewItem)

지정된 항목의 컬렉션 내에 있는 인덱스를 반환합니다.Returns the index within the collection of the specified item.

IndexOfKey(String) IndexOfKey(String) IndexOfKey(String) IndexOfKey(String)

지정된 키를 가진 항목 중 맨 처음 발견되는 항목의 인덱스를 반환합니다.Returns the index of the first occurrence of the item with the specified key.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(Inherited from Object)

명시적 인터페이스 구현

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

해당 컬렉션에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지를 나타내는 값을 가져옵니다.Gets a value indicating whether access to the collection is synchronized (thread safe).

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

컨트롤 컬렉션에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.Gets an object that can be used to synchronize access to the collection of controls.

IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)

컬렉션에 항목을 추가합니다.Adds an item to the collection.

IList.Contains(Object) IList.Contains(Object) IList.Contains(Object) IList.Contains(Object)

지정된 항목이 컬렉션에 있는지 여부를 확인합니다.Determines whether the specified item is located in the collection.

IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object)

컬렉션에서 지정된 항목의 인덱스를 반환합니다.Returns the index, within the collection, of the specified item.

IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object)

항목을 컬렉션 내의 지정된 인덱스에 삽입합니다.Inserts an item into the collection at a specified index.

IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize

컬렉션의 크기가 고정되어 있는지를 나타내는 값을 가져옵니다.Gets a value indicating whether the collection has a fixed size.

IList.Item[Int32] IList.Item[Int32] IList.Item[Int32] IList.Item[Int32]

컬렉션에서 개체를 가져오거나 설정합니다.Gets or sets an object from the collection.

IList.Remove(Object) IList.Remove(Object) IList.Remove(Object) IList.Remove(Object)

컬렉션에서 맨 처음 발견되는 지정된 항목을 제거합니다.Removes the first occurrence of a specified item from the collection.

IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32)

지정한 인덱스에 있는 컬렉션의 항목을 제거합니다.Removes an item from the collection at a specified index.

확장 메서드

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.Converts an IEnumerable to an IQueryable.

적용 대상