ListBox.SelectedIndexCollection クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


ListBox.SelectedIndexCollection クラスは、ListBox 内で選択されている項目のインデックスを格納します。ListBox.SelectedIndexCollection に格納されているインデックスは、ListBox.ObjectCollection クラス内のインデックス位置です。ListBox.ObjectCollection クラスの方は、ListBox に表示されるすべての項目を格納します。
ListBox の項目が ListBox.ObjectCollection にどのように格納されているか、およびそれらの項目の ListBox 内での選択状態を次の表に示します。
前の表の ListBox.ObjectCollection の例に基づいた ListBox.SelectedIndexCollection の内容を次の表に示します。
このクラスのプロパティとメソッドを使用すると、コレクションを使用してさまざまなタスクを実行できます。Contains メソッドを使用すると、ListBox.ObjectCollection クラス内のインデックス位置が、選択されたインデックスを格納する ListBox.SelectedIndexCollection のメンバかどうかを確認できます。このコレクションにインデックス位置があることがわかれば、IndexOf メソッドを使用して、ListBox の ListBox.ObjectCollection 内の特定のインデックス位置が、このコレクション内のどこにあるかを判断できます。

FindString メソッドを使用し、ListBox の項目内から検索テキストのすべてのインスタンスを探し出す方法を次の例に示します。この例では、ListBox 内のすべての項目の連続検索を実行する際の開始検索インデックスを指定できるバージョンの FindString メソッドを使用しています。この例では、再帰的な検索を防ぐために、項目のリストの最後に到達した後、リストの先頭から FindString メソッドが検索を開始するときを判定する方法についても示します。ListBox に項目が見つかったら、SetSelected メソッドを使用して選択されます。
Private Sub FindAllOfMyString(ByVal searchString As String) ' Set the SelectionMode property of the ListBox to select multiple items. listBox1.SelectionMode = SelectionMode.MultiExtended ' Set our intial index variable to -1. Dim x As Integer = -1 ' If the search string is empty exit. If searchString.Length <> 0 Then ' Loop through and find each item that matches the search string. Do ' Retrieve the item based on the previous index found. Starts with -1 which searches start. x = listBox1.FindString(searchString, x) ' If no item is found that matches exit. If x <> -1 Then ' Since the FindString loops infinitely, determine if we found first item again and exit. If ListBox1.SelectedIndices.Count > 0 Then If x = ListBox1.SelectedIndices(0) Then Return End If End If ' Select the item in the ListBox once it is found. ListBox1.SetSelected(x, True) End If Loop While x <> -1 End If End Sub
private void FindAllOfMyString(string searchString) { // Set the SelectionMode property of the ListBox to select multiple items. listBox1.SelectionMode = SelectionMode.MultiExtended; // Set our intial index variable to -1. int x =-1; // If the search string is empty exit. if (searchString.Length != 0) { // Loop through and find each item that matches the search string. do { // Retrieve the item based on the previous index found. Starts with -1 which searches start. x = listBox1.FindString(searchString, x); // If no item is found that matches exit. if (x != -1) { // Since the FindString loops infinitely, determine if we found first item again and exit. if (listBox1.SelectedIndices.Count > 0) { if(x == listBox1.SelectedIndices[0]) return; } // Select the item in the ListBox once it is found. listBox1.SetSelected(x,true); } }while(x != -1); } }
private: void FindAllOfMyString( String^ searchString ) { // Set the SelectionMode property of the ListBox to select multiple items. listBox1->SelectionMode = SelectionMode::MultiExtended; // Set our intial index variable to -1. int x = -1; // If the search string is empty exit. if ( searchString->Length != 0 ) { // Loop through and find each item that matches the search string. do { // Retrieve the item based on the previous index found. Starts with -1 which searches start. x = listBox1->FindString( searchString, x ); // If no item is found that matches exit. if ( x != -1 ) { // Since the FindString loops infinitely, determine if we found first item again and exit. if ( listBox1->SelectedIndices->Count > 0 ) { if ( x == listBox1->SelectedIndices[ 0 ] ) return; } // Select the item in the ListBox once it is found. listBox1->SetSelected( x, true ); } } while ( x != -1 ); } }
private void FindAllOfMyString(String searchString) { // Set the SelectionMode property of the ListBox to // select multiple items. listBox1.set_SelectionMode(SelectionMode.MultiExtended); // Set our intial index variable to -1. int x = -1; // If the search string is empty exit. if (searchString.get_Length() != 0) { // Loop through and find each item that matches the search string. do { // Retrieve the item based on the previous index found. // Starts with -1 which searches start. x = listBox1.FindString(searchString, x); // If no item is found that matches exit. if (x != -1) { // Since the FindString loops infinitely, determine // if we found first item again and exit. if (listBox1.get_SelectedIndices().get_Count() > 0) { if (x == listBox1.get_SelectedIndices().get_Item(0)) { return; } } // Select the item in the ListBox once it is found. listBox1.SetSelected(x, true); } } while (x != -1); } } //FindAllOfMyString } //Form1

System.Windows.Forms.ListBox.SelectedIndexCollection


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ListBox.SelectedIndexCollection コンストラクタ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)



Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ListBox.SelectedIndexCollection プロパティ

名前 | 説明 | |
---|---|---|
![]() | Count | コレクション内の項目の数を取得します。 |
![]() | IsReadOnly | コレクションが読み取り専用かどうかを示す値を取得します。 |
![]() | Item | コレクション内の指定したインデックスにあるインデックス値を取得します。 |

名前 | 説明 | |
---|---|---|
![]() | System.Collections.ICollection.IsSynchronized | このメンバの説明については、ICollection.IsSynchronized のトピックを参照してください。 |
![]() | System.Collections.ICollection.SyncRoot | このメンバの説明については、ICollection.SyncRoot のトピックを参照してください。 |
![]() | System.Collections.IList.IsFixedSize | このメンバの説明については、IList.IsFixedSize のトピックを参照してください。 |
![]() | System.Collections.IList.Item | このメンバの説明については、IList.Item のトピックを参照してください。 |

ListBox.SelectedIndexCollection メソッド

名前 | 説明 | |
---|---|---|
![]() | Add | 指定したインデックス位置に ListBox を追加します。 |
![]() | Clear | コレクションからすべてのコントロールを削除します。 |
![]() | Contains | 指定したインデックスがコレクション内にあるかどうかを確認します。 |
![]() | CopyTo | コレクション全体を既存の配列内の指定した位置にコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetEnumerator | 選択されているインデックス コレクションを反復処理するために使用する列挙子を返します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | IndexOf | ListBox の ListBox.ObjectCollection 内で指定されたインデックスについて、ListBox.SelectedIndexCollection 内におけるインデックスを返します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | Remove | 指定したコントロールをコレクションから削除します。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.Collections.IList.Add | このメンバの説明については、IList.Add のトピックを参照してください。 |
![]() | System.Collections.IList.Clear | このメンバの説明については、IList.Clear のトピックを参照してください。 |
![]() | System.Collections.IList.Contains | このメンバの説明については、IList.Contains のトピックを参照してください。 |
![]() | System.Collections.IList.IndexOf | このメンバの説明については、IList.IndexOf のトピックを参照してください。 |
![]() | System.Collections.IList.Insert | このメンバの説明については、IList.Insert のトピックを参照してください。 |
![]() | System.Collections.IList.Remove | このメンバの説明については、IList.Remove のトピックを参照してください。 |
![]() | System.Collections.IList.RemoveAt | このメンバの説明については、IList.RemoveAt のトピックを参照してください。 |

ListBox.SelectedIndexCollection メンバ
ListBox 内で選択されている項目のインデックスを格納するコレクションを表します。
ListBox.SelectedIndexCollection データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Count | コレクション内の項目の数を取得します。 |
![]() | IsReadOnly | コレクションが読み取り専用かどうかを示す値を取得します。 |
![]() | Item | コレクション内の指定したインデックスにあるインデックス値を取得します。 |

名前 | 説明 | |
---|---|---|
![]() | Add | 指定したインデックス位置に ListBox を追加します。 |
![]() | Clear | コレクションからすべてのコントロールを削除します。 |
![]() | Contains | 指定したインデックスがコレクション内にあるかどうかを確認します。 |
![]() | CopyTo | コレクション全体を既存の配列内の指定した位置にコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetEnumerator | 選択されているインデックス コレクションを反復処理するために使用する列挙子を返します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | IndexOf | ListBox の ListBox.ObjectCollection 内で指定されたインデックスについて、ListBox.SelectedIndexCollection 内におけるインデックスを返します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | Remove | 指定したコントロールをコレクションから削除します。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.Collections.IList.Add | このメンバの説明については、IList.Add のトピックを参照してください。 |
![]() | System.Collections.IList.Clear | このメンバの説明については、IList.Clear のトピックを参照してください。 |
![]() | System.Collections.IList.Contains | このメンバの説明については、IList.Contains のトピックを参照してください。 |
![]() | System.Collections.IList.IndexOf | このメンバの説明については、IList.IndexOf のトピックを参照してください。 |
![]() | System.Collections.IList.Insert | このメンバの説明については、IList.Insert のトピックを参照してください。 |
![]() | System.Collections.IList.Remove | このメンバの説明については、IList.Remove のトピックを参照してください。 |
![]() | System.Collections.IList.RemoveAt | このメンバの説明については、IList.RemoveAt のトピックを参照してください。 |
![]() | System.Collections.ICollection.IsSynchronized | このメンバの説明については、ICollection.IsSynchronized のトピックを参照してください。 |
![]() | System.Collections.ICollection.SyncRoot | このメンバの説明については、ICollection.SyncRoot のトピックを参照してください。 |
![]() | System.Collections.IList.IsFixedSize | このメンバの説明については、IList.IsFixedSize のトピックを参照してください。 |
![]() | System.Collections.IList.Item | このメンバの説明については、IList.Item のトピックを参照してください。 |

Weblioに収録されているすべての辞書からListBox.SelectedIndexCollectionを検索する場合は、下記のリンクをクリックしてください。

- ListBox.SelectedIndexCollectionのページへのリンク