
Dans tous les cas, on peut ramener l'ordre initial des colonnes en utilisant le premier bouton (0-1-2-3), ou revenir à un ordre pré-déterminé par les autre boutons
Ne devrait fonctionner que sous Windows, à cause de l'API.
Note : Il est possible d'utiliser un tableau à la place des datas
Code : Tout sélectionner
; Modifier l'ordre des colonnes dans un ListIconGadget()
; Auteur: Chris
; OS : Windows
; Demo : Non
#MyWindow = 0
#LVM_SETCOLUMNORDERARRAY = #LVM_FIRST + 58
#LVM_GETHEADER = #LVM_FIRST + 31
#HDM_ORDERTOINDEX = #HDM_FIRST + 15
Enumeration
#MyGadget
#MyButton1
#MyButton2
#MyButton3
#MyButton4
#MyButton5
EndEnumeration
Structure MyList
Column.l
Text.s
EndStructure
NewList List.MyList()
Procedure SaveContent() ; Sauve le contenu de chaque colonne dans une liste
Handle = SendMessage_(GadgetID(#MyGadget), #LVM_GETHEADER, 0, 0)
CountColumns = SendMessage_(Handle, #HDM_GETITEMCOUNT, 0, 0)
ClearList(List())
For col = 0 To CountColumns -1
For Line = 0 To CountGadgetItems(#MyGadget) -1
AddElement(List())
List()\Column = col
List()\Text = GetGadgetItemText(#MyGadget, Line, col)
Next
Next
ProcedureReturn
EndProcedure
Procedure ReloadContent() ; Recharge le contenu de chaque colonne
Handle = SendMessage_(GadgetID(#MyGadget), #LVM_GETHEADER, 0, 0)
CountColumns = SendMessage_(Handle, #HDM_GETITEMCOUNT, 0, 0)
For i = 0 To CountColumns -1
col = SendMessage_(Handle, #HDM_ORDERTOINDEX, i, 0)
ForEach List()
If List()\Column = col
SetGadgetItemText(#MyGadget, Line, List()\Text, col) : Line +1
EndIf
Next
Line = 0
Next
ProcedureReturn
EndProcedure
If OpenWindow(#MyWindow,100,100,400,330,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"ListIcon")
If CreateGadgetList(WindowID())
ButtonGadget(#MyButton1, 10, 300, 60, 20, "0-1-2-3")
ButtonGadget(#MyButton2, 80, 300, 60, 20, "1-3-2-0")
ButtonGadget(#MyButton3, 150, 300, 60, 20, "3-0-2-1")
ButtonGadget(#MyButton4, 220, 300, 60, 20, "1-3-0-2")
ButtonGadget(#MyButton5, 290, 300, 60, 20, "2-0-1-3")
ListIconGadget(#MyGadget,5,5,390,290,"Colonne 0",100,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_HeaderDragDrop)
For i = 1 To 3
AddGadgetColumn(#MyGadget, i, "Colonne "+Str(i), 100)
Next
For i = 0 To 10
AddGadgetItem(#MyGadget, -1, "Ligne "+Str(i)+Chr(10)+"Dans"+Chr(10)+"toutes"+Chr(10)+"les colonnes")
Next
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_EventGadget
Select EventGadgetID()
Case #MyButton1
SaveContent()
SendMessage_(GadgetID(#MyGadget), #LVM_SETCOLUMNORDERARRAY, 4, ?Order0)
ReloadContent()
Case #MyButton2
SaveContent()
SendMessage_(GadgetID(#MyGadget), #LVM_SETCOLUMNORDERARRAY, 4, ?Order1)
ReloadContent()
Case #MyButton3
SaveContent()
SendMessage_(GadgetID(#MyGadget), #LVM_SETCOLUMNORDERARRAY, 4, ?Order2)
ReloadContent()
Case #MyButton4
SaveContent()
SendMessage_(GadgetID(#MyGadget), #LVM_SETCOLUMNORDERARRAY, 4, ?Order3)
ReloadContent()
Case #MyButton5
SaveContent()
SendMessage_(GadgetID(#MyGadget), #LVM_SETCOLUMNORDERARRAY, 4, ?Order4)
ReloadContent()
EndSelect
Case #PB_EventCloseWindow
Quit = #True
EndSelect
Until Quit
EndIf
DataSection
Order0:
Data.l 0, 1, 2, 3
Order1 :
Data.l 1, 3, 2, 0
Order2 :
Data.l 3, 0, 2, 1
Order3 :
Data.l 1, 3, 0, 2
Order4 :
Data.l 2, 0, 1, 3
EndDataSection