SelectionMode (Enumeración)
Ensamblado: System.Windows.Forms (en system.windows.forms.dll)
| Nombre de miembro | Descripción | |
|---|---|---|
| MultiExtended | Se pueden seleccionar varios elementos y el usuario puede utilizar las teclas MAYÚS, CTRL y las flechas de dirección para realizar selecciones. | |
| MultiSimple | Se pueden seleccionar varios elementos. | |
| None | No se puede seleccionar ningún elemento. | |
| One | Solamente se puede seleccionar un elemento. |
Clases como ListBox y CheckedListBox utilizan esta enumeración.
En el siguiente ejemplo se muestra la forma de utilizar el método GetSelected para determinar qué elementos de ListBox están seleccionados, a fin de seleccionar los elementos que no están seleccionados y de anular la selección de los elementos seleccionados. En el ejemplo también se muestra la forma de utilizar la propiedad SelectionMode para permitir que un ListBox tenga más de un elemento seleccionado y se utiliza la propiedad Sorted para mostrar la forma de ordenar los elementos de un ListBox de forma automática. En este ejemplo se supone que se ha agregado un ListBox denominado listBox1 a un formulario y que se llama al método InitializeMyListBox definido en el ejemplo desde el evento Load del formulario.
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 void InitializeMyListBox()
{
// Add items to the ListBox.
listBox1.get_Items().Add("A");
listBox1.get_Items().Add("C");
listBox1.get_Items().Add("E");
listBox1.get_Items().Add("F");
listBox1.get_Items().Add("G");
listBox1.get_Items().Add("D");
listBox1.get_Items().Add("B");
// Sort all items added previously.
listBox1.set_Sorted(true);
// Set the SelectionMode to select multiple items.
listBox1.set_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.set_TopIndex(0);
} //InitializeMyListBox
private void InvertMySelection()
{
// Loop through all items the ListBox.
for (int x = 0; x < listBox1.get_Items().get_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.set_TopIndex(0);
} //InvertMySelection
Windows 98, Windows 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter
Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.