![]() |
Zahlen in ListBox1 Sortieren
hoi, nehmen wir mal an ich habe eine listbox in den alle zahlen von 1-1000 sind.
wie sortier ich das, dass es so aussieht: 1 2 3 .. 10 .. 100 .. 1000 ? ich ich einfach Sorted benutze, wird es so sortiert: 1 10 100 2 3 |
Re: Zahlen in ListBox1 Sortieren
Hi,
Du könntest die Items der TListbox einer TStringList zuweisen und diese dann mittels CustomSort Methode sortieren lassen. Am Schluss werden die TStringList Items wieder der TListBox zugewiesen:
Delphi-Quellcode:
function CompareInt(List: TStringList; Index1, Index2: Integer): Integer;
// Wichtig: Keine Fehlerbehandlung, wenn ein Item der List kein Integerwert ist!! var d1, d2: Integer; begin d1 := StrToInt(List[Index1]); d2 := StrToInt(List[Index2]); if d1 < d2 then Result := -1 else if d1 > d2 then Result := 1 else Result := 0; end; procedure TForm1.Button1Click(Sender: TObject); var sl: TStringList; begin sl := TStringList.Create; try // listbox1.Sorted := False; sl.Assign(listbox1.Items); sl.CustomSort(CompareInt); listbox1.Items.Assign(sl); finally sl.Free; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:48 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz