İngilizce dilinde oku

Aracılığıyla paylaş


SelectionMode Sabit listesi

Tanım

Liste kutusunun seçim davranışını belirtir.

C#
[System.Runtime.InteropServices.ComVisible(true)]
public enum SelectionMode
C#
public enum SelectionMode
Devralma
SelectionMode
Öznitelikler

Alanlar

Name Değer Description
MultiExtended 3

Birden çok öğe seçilebilir ve kullanıcı seçim yapmak için SHIFT, CTRL ve ok tuşlarını kullanabilir.

MultiSimple 2

Birden çok öğe seçilebilir.

None 0

Hiçbir öğe seçilemiyor.

One 1

Yalnızca bir öğe seçilebilir.

Örnekler

Aşağıdaki örnekte, seçilmeyen öğeleri seçmek ve seçilen öğelerin seçimini kaldırmak için içindeki hangi öğelerin ListBox seçildiğini belirlemek için yönteminin nasıl kullanılacağı GetSelected gösterilmektedir. Bu örnekte ayrıca, bir öğesinin birden fazla seçili öğeye sahip olmasını sağlamak ListBox için özelliğinin kullanılması SelectionMode gösterilmektedir ve özelliği, içindeki ListBox öğelerin otomatik olarak nasıl sıralanacağını göstermek için kullanılırSorted. Bu örnekte, adlı listBox1adlı bir ListBoxöğesinin bir forma eklendiği ve örnekte tanımlanan yöntemin InitializeMyListBox formun olayından Load çağrıldığı varsayılır.

C#
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;
}

Açıklamalar

Bu numaralandırma ve CheckedListBoxgibi ListBox sınıflar tarafından kullanılır.

Şunlara uygulanır

Ürün Sürümler
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Ayrıca bkz.