다음을 통해 공유


SelectionMode 열거형

정의

목록 상자의 선택 동작을 지정합니다.

public enum class SelectionMode
[System.Runtime.InteropServices.ComVisible(true)]
public enum SelectionMode
public enum SelectionMode
[<System.Runtime.InteropServices.ComVisible(true)>]
type SelectionMode = 
type SelectionMode = 
Public Enum SelectionMode
상속
SelectionMode
특성

필드

Name Description
None 0

항목을 선택할 수 없습니다.

One 1

하나의 항목만 선택할 수 있습니다.

MultiSimple 2

여러 항목을 선택할 수 있습니다.

MultiExtended 3

여러 항목을 선택할 수 있으며 사용자는 Shift, Ctrl 및 화살표 키를 사용하여 선택할 수 있습니다.

예제

다음 예제에서는 선택 되지 않은 항목을 선택 하 고 선택 된 항목을 ListBox 선택 취소 하기 위해 선택 되는 항목을 결정 하는 방법을 사용 GetSelected 하는 방법을 보여 줍니다. 또한 이 예제에서는 속성을 사용하여 SelectionMode 선택한 항목이 두 개 이상 있을 수 있도록 설정하고 ListBox 속성을 사용하여 Sorted 항목을 ListBox 자동으로 정렬하는 방법을 보여 줍니다. 이 예제에서는 이름이 지정된 메서드가 ListBox폼에 추가되었고 예제에 정의된 메서드가 폼 InitializeMyListBox 의 이벤트에서 호출 Load 된다고 가정listBox1합니다.

private:
   void InitializeMyListBox()
   {
      // Add items to the ListBox.
      listBox1->Items->Add( "A" );
      listBox1->Items->Add( "C" );
      listBox1->Items->Add( "E" );
      listBox1->Items->Add( "F" );
      listBox1->Items->Add( "G" );
      listBox1->Items->Add( "D" );
      listBox1->Items->Add( "B" );

      // Sort all items added previously.
      listBox1->Sorted = true;

      // Set the SelectionMode to select multiple items.
      listBox1->SelectionMode = SelectionMode::MultiExtended;

      // Select three initial items from the list.
      listBox1->SetSelected( 0, true );
      listBox1->SetSelected( 2, true );
      listBox1->SetSelected( 4, true );

      // Force the ListBox to scroll back to the top of the list.
      listBox1->TopIndex = 0;
   }

   void InvertMySelection()
   {
      // Loop through all items the ListBox.
      for ( int x = 0; x < listBox1->Items->Count; x++ )
      {
         // Select all items that are not selected,
         // deselect all items that are selected.
         listBox1->SetSelected( x,  !listBox1->GetSelected( x ) );
      }
      listBox1->TopIndex = 0;
   }
private void InitializeMyListBox()
{
   // Add items to the ListBox.
   listBox1.Items.Add("A");
   listBox1.Items.Add("C");
   listBox1.Items.Add("E");
   listBox1.Items.Add("F");
   listBox1.Items.Add("G");
   listBox1.Items.Add("D");
   listBox1.Items.Add("B");

   // Sort all items added previously.
   listBox1.Sorted = true;

   // Set the SelectionMode to select multiple items.
   listBox1.SelectionMode = SelectionMode.MultiExtended;

   // Select three initial items from the list.
   listBox1.SetSelected(0,true);
   listBox1.SetSelected(2,true);
   listBox1.SetSelected(4,true);

   // Force the ListBox to scroll back to the top of the list.
   listBox1.TopIndex=0;
}

private void InvertMySelection()
{
   // Loop through all items the ListBox.
   for (int x = 0; x < listBox1.Items.Count; x++)
   {
      // Determine if the item is selected.
      if (listBox1.GetSelected(x))
         // Deselect all items that are selected.
         listBox1.SetSelected(x,false);      
      else
         // Select all items that are not selected.
         listBox1.SetSelected(x,true);
   }
   // Force the ListBox to scroll back to the top of the list.
   listBox1.TopIndex=0;
}
Private Sub InitializeMyListBox()
   ' Add items to the ListBox.
   listBox1.Items.Add("A")
   listBox1.Items.Add("C")
   listBox1.Items.Add("E")
   listBox1.Items.Add("F")
   listBox1.Items.Add("G")
   listBox1.Items.Add("D")
   listBox1.Items.Add("B")

   ' Sort all items added previously.
   listBox1.Sorted = True

   ' Set the SelectionMode to select multiple items.
   listBox1.SelectionMode = SelectionMode.MultiExtended

   ' Select three initial items from the list.
   listBox1.SetSelected(0, True)
   listBox1.SetSelected(2, True)
   listBox1.SetSelected(4, True)

   ' Force the ListBox to scroll back to the top of the list.
   listBox1.TopIndex = 0
End Sub

Private Sub InvertMySelection()

   Dim x As Integer
   ' Loop through all items the ListBox.
   For x = 0 To listBox1.Items.Count - 1

      ' Determine if the item is selected.
      If listBox1.GetSelected(x) = True Then
         ' Deselect all items that are selected.
         listBox1.SetSelected(x, False)
      Else
         ' Select all items that are not selected.
         listBox1.SetSelected(x, True)
      End If
   Next x
   ' Force the ListBox to scroll back to the top of the list.
   listBox1.TopIndex = 0
End Sub

설명

이 열거형은 다음과 같은 ListBoxCheckedListBox클래스에서 사용됩니다.

적용 대상

추가 정보