TListBoxSorted (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses an edit box, a list box, and two buttons on a form. The buttons are named Add and Sort. When you click the Add button, the text in the edit box is added to the list in the list box. Before you click the Sort button, any new items are added to the end of the list. After you click the Sort button, the list in the list box is sorted and remains sorted, even if additional strings are added. If you click the Sort button again, the list box remains sorted, but any new strings are again added to the end of the list.


Code

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  ListBox1->Items->Add("Not");
  ListBox1->Items->Add("In");
  ListBox1->Items->Add("Alphabetical");
  ListBox1->Items->Add("Order");
}

void __fastcall TForm1::AddClick(TObject *Sender)
{
  ListBox1->Items->Add(Edit1->Text);
}

void __fastcall TForm1::SortClick(TObject *Sender)
{
  ListBox1->Sorted = True;
}

Uses