TListBoxSorted (Delphi)
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 clicks the sort button again, the list box remains sorted, but any new strings are again added to the end of the list.
Code
procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Items.Add('Not');
ListBox1.Items.Add('In');
ListBox1.Items.Add('Alphabetical');
ListBox1.Items.Add('Order');
end;
procedure TForm1.AddClick(Sender: TObject);
begin
ListBox1.Items.Add(Edit1.Text);
end;
procedure TForm1.SortClick(Sender: TObject);
begin
ListBox1.Sorted := True;
end;
Uses
- Vcl.StdCtrls.TCustomListBox.Sorted ( fr | de | ja )