Hola ale4132.
Un modo simple:
Código Delphi
[-]
procedure SortListBox(ListBox: TListBox; Asc: Boolean = True);
var
i,j: Integer;
aux: string;
Change: Boolean;
begin
with ListBox do
begin
Items.BeginUpdate;
for i:= 0 to Items.Count-2 do
for j:= i+1 to Items.Count-1 do
begin
if Asc then
Change:= StrToInt(Items[i]) > StrToInt(Items[j])
else
Change:= StrToInt(Items[i]) < StrToInt(Items[j]);
if Change then
begin
aux := Items[i];
Items[i]:= Items[j];
Items[j]:= aux;
end;
end;
Items.EndUpdate;
end;
end;
Llamada ejemplo:
Código Delphi
[-]
procedure TForm1.btnSortClick(Sender: TObject);
begin
SortListBox(ListBox1, CheckBoxDesc.Checked);
end;
Donde la condición de ordenamiento ascendente o descendente depende de la propiedad
Checked de un CheckBox.
Saludos.