ListBox.SelectedIndexCollectionとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ListBox.SelectedIndexCollectionの意味・解説 

ListBox.SelectedIndexCollection クラス

ListBox 内で選択されている項目のインデックス格納するコレクション表します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Class SelectedIndexCollection
    Implements IList, ICollection, IEnumerable
Dim instance As SelectedIndexCollection
public class SelectedIndexCollection : IList,
 ICollection, IEnumerable
public ref class SelectedIndexCollection :
 IList, ICollection, IEnumerable
public class SelectedIndexCollection implements
 IList, ICollection, 
    IEnumerable
public class SelectedIndexCollection implements
 IList, ICollection, 
    IEnumerable
解説解説

ListBox.SelectedIndexCollection クラスは、ListBox 内で選択されている項目のインデックス格納しますListBox.SelectedIndexCollection格納されているインデックスは、ListBox.ObjectCollection クラス内のインデックス位置です。ListBox.ObjectCollection クラスの方は、ListBox表示されるすべての項目を格納します

ListBox の項目が ListBox.ObjectCollectionどのように格納されているか、およびそれらの項目の ListBox 内での選択状態を次の表に示します

インデックス

項目

ListBox 内の選択状態

0

object1

選択されていない

1

object2

選択されている

2

object3

選択されていない

3

object4

選択されている

4

object5

選択されている

前の表の ListBox.ObjectCollection の例に基づいた ListBox.SelectedIndexCollection内容次の表に示します

インデックス

ObjectCollection 内の選択されている項目のインデックス

0

1

1

3

2

4

このクラスプロパティメソッド使用すると、コレクション使用してさまざまなタスク実行できます。Contains メソッド使用すると、ListBox.ObjectCollection クラス内のインデックス位置が、選択されインデックス格納する ListBox.SelectedIndexCollectionメンバかどうか確認できます。このコレクションインデックス位置があることがわかれば、IndexOf メソッド使用してListBoxListBox.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.Object
  System.Windows.Forms.ListBox.SelectedIndexCollection
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ListBox.SelectedIndexCollection コンストラクタ

ListBox.SelectedIndexCollection クラス新しインスタンス初期化します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Dim owner As ListBox

Dim instance As New SelectedIndexCollection(owner)
public SelectedIndexCollection (
    ListBox owner
)
public:
SelectedIndexCollection (
    ListBox^ owner
)
public SelectedIndexCollection (
    ListBox owner
)
public function SelectedIndexCollection (
    owner : ListBox
)

パラメータ

owner

コレクション所有者を表す ListBox

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ListBox.SelectedIndexCollection クラス
ListBox.SelectedIndexCollection メンバ
System.Windows.Forms 名前空間

ListBox.SelectedIndexCollection プロパティ


パブリック プロパティパブリック プロパティ

明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 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 クラス
System.Windows.Forms 名前空間

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 から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 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 クラス
System.Windows.Forms 名前空間

ListBox.SelectedIndexCollection メンバ

ListBox 内で選択されている項目のインデックス格納するコレクション表します

ListBox.SelectedIndexCollection データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド ListBox.SelectedIndexCollection 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 から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 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 のトピック参照してください
参照参照

関連項目

ListBox.SelectedIndexCollection クラス
System.Windows.Forms 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ListBox.SelectedIndexCollection」の関連用語

ListBox.SelectedIndexCollectionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ListBox.SelectedIndexCollectionのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS