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

定義

リスト ビュー コントロールにある、選択された項目のコレクションを表します。Represents the collection of selected items in a list view control.

public: ref 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
Public Class ListView.SelectedListViewItemCollection
Implements IList
継承
ListView.SelectedListViewItemCollectionListView.SelectedListViewItemCollectionListView.SelectedListViewItemCollectionListView.SelectedListViewItemCollection
属性
実装

次のコード例に示しますを使用して、 SelectedItemsSelectedIndexChangedイベント、およびHeaderStyleメンバーとListView.SelectedListViewItemCollectionクラス。The following code example demonstrates using the SelectedItems, SelectedIndexChanged event, and HeaderStyle members and the ListView.SelectedListViewItemCollection class. この例を実行するを含む形式で次のコードを貼り付け、ListViewという名前のオブジェクトListView1TextBoxというTextBox1To 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;
 
	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

注釈

AListView.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.

適用対象