ListView.SelectedListViewItemCollection 클래스

정의

list view 컨트롤에서 선택된 항목의 컬렉션을 나타냅니다.

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

예제

다음 코드 예제를 사용 하 여 보여 줍니다. SelectedItems는 , SelectedIndexChanged 이벤트 및 HeaderStyle 멤버 및 ListView.SelectedListViewItemCollection 클래스입니다. 이 예제를 실행하려면 라는 개체와 TextBox 라는 ListView1TextBox1개체가 포함된 ListView 양식에 다음 코드를 붙여넣습니다. 폼의 InitializeListView 생성자 또는 이벤트 처리기에서 메서드를 Load 호출합니다. 이 예제에서는 이벤트 처리기가 이벤트와 올바르게 연결되어야 합니다 SelectedIndexChanged .

// 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
// 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 = 
        this.ListView1.SelectedItems;
    
    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 = _
        Me.ListView1.SelectedItems
    Dim item As ListViewItem
    Dim price As Double = 0.0
    For Each item In breakfast
        price += Double.Parse(item.SubItems(1).Text)
    Next

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

설명

ListView.SelectedListViewItemCollection 선택한 항목을 컨트롤에 ListView 저장합니다. 에 저장된 항목은 에 ListView.SelectedListViewItemCollectionListView.ListViewItemCollection포함된 항목입니다. 는 ListView.ListViewItemCollection 에 표시된 모든 항목을 저장합니다 ListView.

다음 표에서는 의 항목과 선택 상태를 예제 컨트롤에 저장하는 방법 ListView.ListViewItemCollectionListView 예를 보여 ListView 있습니다.

인덱스 항목 ListView의 선택 상태
0 Item1 선택 취소
1 Item2 선택됨
2 item3 선택 취소
3 Item4 선택됨
4 Item5 선택됨

이전 표의 ListView.ListViewItemCollection 예제를 기반으로 다음 표에서는 가 ListView.SelectedListViewItemCollection 표시되는 방식을 보여 줍니다.

인덱스 ListViewItemCollection에서 선택한 항목
0 Item2
1 Item4
2 Item5

이 클래스의 속성 및 메서드를 사용하여 컬렉션에서 다양한 작업을 수행할 수 있습니다. Contains 메서드를 사용하면 클래스의 항목 ListView.ListViewItemCollection 이 의 ListView.SelectedListViewItemCollection멤버인지 여부를 확인할 수 있습니다. 항목이 컬렉션에 있다는 것을 알게 되면 메서드를 IndexOf 사용하여 에서 ListView.SelectedListViewItemCollection항목의 위치를 확인할 수 있습니다.

생성자

ListView.SelectedListViewItemCollection(ListView)

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

속성

Count

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

IsReadOnly

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

Item[Int32]

컬렉션 내의 지정된 인덱스에 위치하는 항목을 가져옵니다.

Item[String]

컬렉션에서 지정된 키를 가진 항목을 가져옵니다.

메서드

Clear()

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

Contains(ListViewItem)

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

ContainsKey(String)

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

CopyTo(Array, Int32)

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

Equals(Object)

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

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

선택된 항목 컬렉션 전체를 반복하는 데 사용할 수 있는 열거자를 반환합니다.

GetHashCode()

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

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

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

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

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

IndexOfKey(String)

지정된 키를 가진 항목 중 맨 처음 발견되는 항목의 인덱스를 반환합니다.

MemberwiseClone()

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

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

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

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.IsSynchronized

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

ICollection.SyncRoot

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

IList.Add(Object)

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

IList.Contains(Object)

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

IList.IndexOf(Object)

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

IList.Insert(Int32, Object)

항목을 컬렉션 내의 지정된 인덱스에 삽입합니다.

IList.IsFixedSize

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

IList.Item[Int32]

컬렉션에서 개체를 가져오거나 설정합니다.

IList.Remove(Object)

컬렉션에서 맨 처음 발견되는 지정된 항목을 제거합니다.

IList.RemoveAt(Int32)

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

확장 메서드

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

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

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상