/* HAUPTPROGRAMM */
Declarar Handle gb, btn1, btn2, btn3, btn4, btn5, btn6, Largo ende
Ventana 600, 400
btn1 = Crear("Button", %HWnd, "ASC", 10, 10, 60, 25)
btn2 = Crear("Button", %HWnd, "DESC", 10, 40, 60, 25)
btn3 = Crear("Button", %HWnd, "ASC", 100, 10, 60, 25)
btn4 = Crear("Button", %HWnd, "DESC", 100, 40, 60, 25)
btn5 = Crear("Button", %HWnd, "ASC", 190, 10, 60, 25)
btn6 = Crear("Button", %HWnd, "DESC", 190, 40, 60, 25)
gb = Crear("Gridbox",%HWnd, "DATUM;0;80;MENGE;0;80;ARTIKEL;0;120", 0, 10, 70, 300, 150)
AddStrings(gb, "20.10.2015|500|Tomaten")
AddStrings(gb, "15.12.2017|200|Birnen")
AddStrings(gb, "22.11.2015|100|Ananas")
AddStrings(gb, "10.04.2016|50|Äpfel")
AddStrings(gb, "11.10.2017|1000|Zitronen")
AddStrings(gb, "01.04.2017|1500|Kirschen")
' SetHeader_SetArrow(gb, 0, 0)
ende = 0
Sinestar encargado 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
FIN
PROC SortListview
' ACHTUNG : verwendet el interne Listboxliste (propio Daten vorher con Move o.ä. sichern)
' lv : Handle el Gridbox
' spalte : Nullbasierend (1. Spalte = 0)
' SortType : Spalteninhalt (1 = STRINGS, 2 = DATUM (tt.mm.jjjj), 3 = ZAHLEN)
' Order : 0 = aufsteigend, 1 = absteigend
Parámetros Handle lv, Largo spalte, SortType, Order
DECLARE Handle liste, LONG sOrder, sTyp, STRING item, zeile, Float datum
liste = Crear("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))
AddStrings(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)))
AddStrings(0, zeile)
ENDWHILE
ELSE
CLEARLIST 0
MOVE("HandleToList", lv)
SortList "|", spalte + 1, (sTyp * sOrder)
ENDIF
CLEARLIST lv
MOVE("ListToHandle", lv)
CLEARLIST 0
ENDPROC