ListBox.SelectionMode Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
içinde öğelerin seçildiği ListBoxyöntemi alır veya ayarlar.
public:
virtual property System::Windows::Forms::SelectionMode SelectionMode { System::Windows::Forms::SelectionMode get(); void set(System::Windows::Forms::SelectionMode value); };
public virtual System.Windows.Forms.SelectionMode SelectionMode { get; set; }
member this.SelectionMode : System.Windows.Forms.SelectionMode with get, set
Public Overridable Property SelectionMode As SelectionMode
Özellik Değeri
Değerlerden SelectionMode biri. Varsayılan değer: SelectionMode.One.
Özel durumlar
Atanan değer değerlerden biri SelectionMode değildir.
Örnekler
Aşağıdaki kod örneği, 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ğını GetSelected gösterir. Örnekte ayrıca, bir öğesinin SelectionMode birden çok seçili öğeye sahip olmasını sağlamak ListBox için özelliğinin kullanılması gösterilmektedir ve otomatik olarak öğeleri ListBox sıralamayı göstermek için özelliğini kullanırSorted. Bu örnek, adlı bir ListBoxöğesinin forma eklenmesini ve InitializeMyListBox örnekte tanımlanan yöntemin formun olayından Load çağrılmış olmasını listBox1gerektirir.
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
Açıklamalar
özelliği, SelectionMode bir kullanıcıda bir kerede ListBox kaç öğe seçebileceğini ve kullanıcının birden çok seçim yapmasını belirlemenizi sağlar.
SelectionMode Özelliği olarak ayarlandığında, SHIFT tuşuna SelectionMode.MultiExtendedbasıp fareye tıklamak veya SHIFT tuşuna basmak ve ok tuşlarından biri (YUKARI OK, AŞAĞI OK, SOL OK ve SAĞ OK) seçimi daha önce seçilen öğeden geçerli öğeye genişletir. CTRL tuşuna basıp fareye tıklanması listedeki bir öğeyi seçer veya seçimini kaldırır. özelliği olarak SelectionMode.MultiSimpleayarlandığında, ARA ÇUBUĞU'na fareyle tıklandığında veya basıldığında listedeki bir öğe seçilir veya seçimi kaldırılır.