/* HAUPTPROGRAMM */
Declare Handle gb, btn1, btn2, btn3, btn4, btn5, btn6, Long ende
Window 600, 400
btn1 = Create("Button", %HWnd, "ASC", 10, 10, 60, 25)
btn2 = Create("Button", %HWnd, "DESC", 10, 40, 60, 25)
btn3 = Create("Button", %HWnd, "ASC", 100, 10, 60, 25)
btn4 = Create("Button", %HWnd, "DESC", 100, 40, 60, 25)
btn5 = Create("Button", %HWnd, "ASC", 190, 10, 60, 25)
btn6 = Create("Button", %HWnd, "DESC", 190, 40, 60, 25)
gb = Create("Gridbox",%HWnd, "DATUM;0;80;MENGE;0;80;ARTIKEL;0;120", 0, 10, 70, 300, 150)
AddString(gb, "20.10.2015|500|Tomaten")
AddString(gb, "15.12.2017|200|Birnen")
AddString(gb, "22.11.2015|100|Ananas")
AddString(gb, "10.04.2016|50|Äpfel")
AddString(gb, "11.10.2017|1000|Zitronen")
AddString(gb, "01.04.2017|1500|Kirschen")
' SetHeader_SetArrow(gb, 0, 0)
ende = 0
WhileNot ende
WaitInput
If Clicked(btn1)
SortListview(gb, 0, 2, 0)
ElseIf Clicked(btn2)
SortListview(gb, 0, 2, 1)
ElseIf Clicked(btn3)
SortListview(gb, 1, 3, 0)
ElseIf Clicked(btn4)
SortListview(gb, 1, 3, 1)
Elseif Clicked(btn5)
SortListview(gb, 2, 1, 0)
ElseIf Clicked(btn6)
SortListview(gb, 2, 1, 1)
EndIf
Case %Key = 2 : ende = 1
EndWhile
END
PROC SortListview
' ACHTUNG : verwendet die interne Listboxliste (eigene Daten vorher mit Move o.ä. sichern)
' lv : Handle der Gridbox
' spalte : Nullbasierend (1. Spalte = 0)
' SortType : Spalteninhalt (1 = STRINGS, 2 = DATUM (tt.mm.jjjj), 3 = ZAHLEN)
' Order : 0 = aufsteigend, 1 = absteigend
Parameters Handle lv, Long spalte, SortType, Order
DECLARE Handle liste, LONG sOrder, sTyp, STRING item, zeile, Float datum
liste = Create("List", 0)
SELECT SortType
CASEOF 1
sTyp = 4' entsprechend Gebietsschema
CASEOF 2
sTyp = 5
CASEOF 3
sTyp = 5
ENDSELECT
Select Order
CaseOf 0
sOrder = 1
CASEOF 1
sOrder = -1
ENDSELECT
IF SortType = 2' DATUM - SORTIERUNG
CLEARLIST 0
MOVE("HandleToList", lv)
WHILELOOP 0, GETCOUNT(0) -1
item = SubStr$(GetSTRING$(0, &LOOP), spalte + 1, "|")
datum = Str$(DT("SetDate", item))
zeile = Translate$(GetString$(0, &LOOP), item, Str$(datum))
AddString(liste, zeile)
ENDWHILE
CLEARLIST 0
MOVE("HandleToList", liste)
SortList "|", spalte + 1, (sTyp * sOrder)
CLEARLIST liste
MOVE("ListToHandle", liste)
CLEARLIST 0
WHILELOOP 0, GETCOUNT(liste) - 1
item = SubStr$(GetString$(liste, &LOOP), spalte + 1, "|")
zeile = Translate$(GetString$(liste, &LOOP), item, DT("GetDate", 0, VAL(item)))
AddString(0, zeile)
ENDWHILE
ELSE
CLEARLIST 0
MOVE("HandleToList", lv)
SortList "|", spalte + 1, (sTyp * sOrder)
ENDIF
CLEARLIST lv
MOVE("ListToHandle", lv)
CLEARLIST 0
ENDPROC