ListBox.SelectedIndexCollection 클래스

정의

ListBox에서 선택된 항목에 대해 인덱스가 들어 있는 컬렉션을 나타냅니다.

public: ref class ListBox::SelectedIndexCollection : System::Collections::IList
public class ListBox.SelectedIndexCollection : System.Collections.IList
type ListBox.SelectedIndexCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
Public Class ListBox.SelectedIndexCollection
Implements IList
상속
ListBox.SelectedIndexCollection
구현

예제

다음 예제에서는 메서드를 사용하여 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.SelectedIndexCollection 인덱스를 선택한 항목 ListBox에 저장합니다. 인덱스에 저장된 ListBox.SelectedIndexCollection 인덱스는 클래스 내의 ListBox.ObjectCollection 인덱스 위치입니다. 클래스는 ListBox.ObjectCollection 에 표시된 ListBox모든 항목을 저장합니다.

다음 표는 항목과 선택 상태를 예제 내에 저장하는 방법 ListBox.ObjectCollectionListBoxListBox입니다.

인덱스 항목 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 사용하여 해당 항목 내 ListBox.ObjectCollection 의 특정 인덱스 ListBox 위치가 저장되는 위치를 확인할 수 있습니다.

생성자

ListBox.SelectedIndexCollection(ListBox)

ListBox.SelectedIndexCollection 클래스의 새 인스턴스를 초기화합니다.

속성

Count

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

IsReadOnly

컬렉션이 읽기 전용인지를 나타내는 값을 가져옵니다.

Item[Int32]

이 컬렉션에서 지정된 인덱스의 인덱스 값을 가져옵니다.

메서드

Add(Int32)

지정된 인덱스 위치에 ListBox를 추가합니다.

Clear()

컬렉션에서 컨트롤을 모두 제거합니다.

Contains(Int32)

지정된 인덱스가 컬렉션에 위치하는지 여부를 확인합니다.

CopyTo(Array, Int32)

배열 내의 지정된 위치에서 기존 배열로 전체 컬렉션을 복사합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetEnumerator()

선택된 인덱스 컬렉션 전체를 반복하는 데 사용할 열거자를 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IndexOf(Int32)

ListBox.SelectedIndexCollectionListBox.ObjectCollection에서 지정된 인덱스의 ListBox 내 인덱스를 반환합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Remove(Int32)

지정된 컨트롤을 컬렉션에서 제거합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.IsSynchronized

이 멤버에 대한 설명은 IsSynchronized를 참조하세요.

ICollection.SyncRoot

이 멤버에 대한 설명은 SyncRoot를 참조하세요.

IList.Add(Object)

이 멤버에 대한 설명은 Add(Object)를 참조하세요.

IList.Clear()

이 멤버에 대한 설명은 Clear()를 참조하세요.

IList.Contains(Object)

이 멤버에 대한 설명은 Contains(Object)를 참조하세요.

IList.IndexOf(Object)

이 멤버에 대한 설명은 IndexOf(Object)를 참조하세요.

IList.Insert(Int32, Object)

이 멤버에 대한 설명은 Insert(Int32, Object)를 참조하세요.

IList.IsFixedSize

이 멤버에 대한 설명은 IsFixedSize를 참조하세요.

IList.Item[Int32]

이 멤버에 대한 설명은 Item[Int32]를 참조하세요.

IList.Remove(Object)

이 멤버에 대한 설명은 Remove(Object)를 참조하세요.

IList.RemoveAt(Int32)

이 멤버에 대한 설명은 RemoveAt(Int32)를 참조하세요.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상