ListBox.SelectedIndexCollection.Count 속성

정의

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

public:
 property int Count { int get(); };
[System.ComponentModel.Browsable(false)]
public int Count { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Count : int
Public ReadOnly Property Count As Integer

속성 값

Int32

컬렉션의 항목 수입니다.

구현

특성

예제

다음 예제에서는 메서드를 사용하여 FindString 항목 ListBox에서 검색 텍스트의 모든 인스턴스를 검색하는 방법을 보여 줍니다. 이 예제에서는 모든 항목을 ListBox지속적으로 검색할 시작 검색 인덱스를 지정할 수 있는 메서드 버전을 FindString 사용합니다. 이 예제에서는 재귀 검색을 방지하기 위해 항목 목록의 맨 아래에 도달한 후 메서드가 목록 맨 위에서 검색을 시작하는 시점 FindString 을 확인하는 방법도 보여 줍니다. 항목이 발견되면 메서드를 ListBox사용하여 SetSelected 선택됩니다.

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

설명

이 속성을 사용하면 에서 선택한 항목의 수를 확인할 수 있습니다 ListBox. 그런 다음 컬렉션의 값을 반복할 때 이 값을 사용할 수 있으며 루프를 수행하기 위해 여러 반복을 제공해야 합니다. 속성 ListBoxSelectionMode 설정되거나 SelectionMode.MultiExtended설정 SelectionMode.MultiSimple 되지 않는 한 이 속성은 선택한 항목이 있는지 여부에 따라 항상 0 또는 1의 값을 반환합니다.

적용 대상