SelectionMode Enumeración

Definición

Especifica el comportamiento de selección de un cuadro de lista.Specifies the selection behavior of a list box.

public enum class SelectionMode
[System.Runtime.InteropServices.ComVisible(true)]
public enum SelectionMode
type SelectionMode = 
Public Enum SelectionMode
Herencia
SelectionMode
Atributos

Campos

MultiExtended 3

Se pueden seleccionar varios elementos y el usuario puede presionar MAYÚS, CTRL y las teclas de dirección para realizar selecciones.Multiple items can be selected, and the user can use the SHIFT, CTRL, and arrow keys to make selections.

MultiSimple 2

Se pueden seleccionar varios elementos.Multiple items can be selected.

None 0

No se puede seleccionar ningún elemento.No items can be selected.

One 1

Solamente se puede seleccionar un elemento.Only one item can be selected.

Ejemplos

En el ejemplo siguiente se muestra cómo usar el método GetSelected para determinar qué elementos de un ListBox están seleccionados para seleccionar los elementos que no están seleccionados y anular la selección de los elementos seleccionados.The following example demonstrates how to use the GetSelected method to determine which items in a ListBox are selected in order to select the items that are not selected and deselect the items that are selected. En el ejemplo también se muestra cómo usar la propiedad SelectionMode para permitir que un ListBox tenga más de un elemento seleccionado y utiliza la propiedad Sorted para mostrar cómo se ordenan los elementos de un ListBox automáticamente.The example also demonstrates using the SelectionMode property to enable a ListBox to have more than one selected item and uses the Sorted property to demonstrate how to sort items in a ListBox automatically. En este ejemplo se da por supuesto que se ha agregado un ListBox, denominado listBox1, a un formulario y que el método InitializeMyListBox definido en el ejemplo se llama desde el evento Load del formulario.This example assumes that a ListBox, named listBox1, has been added to a form and that the InitializeMyListBox method defined in the example is called from the Load event of the form.

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) == true)
         // 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

Comentarios

Esta enumeración la usan las clases como ListBox y CheckedListBox.This enumeration is used by classes such as ListBox and CheckedListBox.

Se aplica a

Consulte también: