ListBox.Sorted Ö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çindeki ListBox öğelerin alfabetik olarak sıralanıp sıralanmadığını belirten bir değer alır veya ayarlar.
public:
property bool Sorted { bool get(); void set(bool value); };
public bool Sorted { get; set; }
member this.Sorted : bool with get, set
Public Property Sorted As Boolean
Özellik Değeri
true denetimdeki öğeler sıralanmışsa; aksi takdirde , false. Varsayılan değer: false.
Ö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
Sorted dizelerini bir içinde ListBoxotomatik olarak alfabetik olarak sıralamak için özelliğini kullanın. Öğeler sıralanmış ListBoxbir öğesine eklendikçe, öğeler sıralanmış listede uygun konuma taşınır. öğesine ListBoxöğe eklerken, önce öğeleri sıralamak ve sonra yeni öğeler eklemek daha verimli olur.
ayarına sahip Sorted olan A trueListBox, özelliğini kullanan DataSource verilere bağlı olmamalıdır. Bağlı ListBoxbir içinde sıralanmış verileri görüntülemek için, sıralamayı destekleyen bir veri kaynağına bağlamanız ve veri kaynağının sıralamayı sağlaması gerekir.