ListBox.SelectedIndexCollection.Count プロパティとは? わかりやすく解説

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

ListBox.SelectedIndexCollection.Count プロパティ

コレクション内の項目の数を取得します

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

解説解説

このプロパティ使用すると、ListBox 内で選択されている項目の数を確認できます。この値は、コレクションの値をループするときに、ループ反復回数指定する必要がある場合使用できますListBox の SelectionMode プロパティSelectionMode.MultiSimple または SelectionMode.MultiExtendedいずれかに設定されていない限り、このプロパティは、選択されている項目があるかどうかに応じて常に 0 または 1 の値を返します

使用例使用例

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ListBox.SelectedIndexCollection クラス
ListBox.SelectedIndexCollection メンバ
System.Windows.Forms 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からListBox.SelectedIndexCollection.Count プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からListBox.SelectedIndexCollection.Count プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からListBox.SelectedIndexCollection.Count プロパティ を検索

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

辞書ショートカット

すべての辞書の索引

ListBox.SelectedIndexCollection.Count プロパティのお隣キーワード
検索ランキング

   

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



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

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

©2025 GRAS Group, Inc.RSS