ListView.SelectedIndexCollection 클래스

정의

ListView 컨트롤의 선택된 항목에 대한 인덱스를 포함하는 컬렉션을 나타냅니다.

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

예제

다음 코드 예제에서는 사용 하는 방법을 보여 줍니다는 SelectedIndices, SelectedIndexChanged및 멤버 및 HeaderStyleListView.SelectedIndexCollection 클래스입니다. 이 예제를 실행하려면 다음 코드를 라는 개체와 라는 ListView1TextBox1개체가 포함된 ListView 양식에 TextBox 붙여넣습니다. 폼의 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 SelectedIndices property to retrieve and tally the  
// price of the selected menu items.
void ListView1_SelectedIndexChanged_UsingIndices( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   ListView::SelectedIndexCollection^ indexes = this->ListView1->SelectedIndices;
   double price = 0.0;
   System::Collections::IEnumerator^ myEnum1 = indexes->GetEnumerator();
   while ( myEnum1->MoveNext() )
   {
      int index = safe_cast<int>(myEnum1->Current);
      price += Double::Parse( this->ListView1->Items[ index ]->SubItems[ 1 ]->Text );
   }

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

    ListView.SelectedIndexCollection indexes = 
        this.ListView1.SelectedIndices;
    
    double price = 0.0;
    foreach ( int index in indexes )
    {
        price += Double.Parse(
            this.ListView1.Items[index].SubItems[1].Text);
    }

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

    Dim indexes As ListView.SelectedIndexCollection = _
        Me.ListView1.SelectedIndices
    Dim index As Integer
    Dim price As Double = 0.0
    For Each index In indexes
        price += Double.Parse(Me.ListView1.Items(index).SubItems(1).Text)
    Next

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

설명

ListView.SelectedIndexCollection 컨트롤에서 선택한 항목 ListView 에 인덱스를 저장합니다. 에 ListView.SelectedIndexCollection 저장된 인덱스는 내 ListView.ListViewItemCollection의 인덱스 위치입니다. 는 ListView.ListViewItemCollection 컨트롤에 ListView 표시된 모든 항목을 저장합니다.

다음 표에서는 의 항목을 ListView 저장하는 방법 ListView.ListViewItemCollection 의 예를 보여 하며, 해당 선택 상태를 예제ListView에 표시합니다.

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

이전 표의 ListView.ListViewItemCollection 예제에 따라 다음 표에서는 가 ListView.SelectedIndexCollection 표시되는 방법을 보여 줍니다.

인덱스 ListViewItemCollection에서 선택한 항목의 인덱스
0 1
1 3
2 4

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

생성자

ListView.SelectedIndexCollection(ListView)

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

속성

Count

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

IsReadOnly

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

Item[Int32]

이 컬렉션에서 지정된 인덱스의 인덱스 값을 가져옵니다.

메서드

Add(Int32)

Items 배열의 지정된 인덱스에 있는 항목을 컬렉션에 추가합니다.

Clear()

컬렉션의 항목을 지웁니다.

Contains(Int32)

지정된 인덱스가 컬렉션에 위치하는지 여부를 확인합니다.

CopyTo(Array, Int32)

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

Equals(Object)

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

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

선택된 인덱스 컬렉션을 반복하는 데 사용할 수 있는 열거자를 반환합니다.

GetHashCode()

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

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

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

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

ListView.SelectedIndexCollection 컨트롤의 ListView.ListViewItemCollection에 있는 지정된 인덱스의 ListView 내 인덱스를 반환합니다.

MemberwiseClone()

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

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

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

ToString()

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

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.IsSynchronized

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

ICollection.SyncRoot

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

IList.Add(Object)

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

IList.Clear()

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

IList.Contains(Object)

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

IList.IndexOf(Object)

이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다.

ListView.SelectedIndexCollection의 인덱스를 반환합니다. ListView.SelectedIndexCollection에는 ListView.ListViewItemCollection 컨트롤의 ListView에 있는 선택된 항목의 인덱스가 포함되어 있습니다.

IList.Insert(Int32, Object)

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

IList.IsFixedSize

ListView.SelectedIndexCollection의 크기가 고정되어 있는지 여부를 나타내는 값을 가져옵니다.

IList.Item[Int32]

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

IList.Remove(Object)

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

IList.RemoveAt(Int32)

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

확장 메서드

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

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

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상