Posted: Wed Dec 21, 2005 9:42 pm
Thanks a lot 

http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
;/ PureLVSort 4.0 Test
Enumeration
#List
#Button
EndEnumeration
Procedure AddData()
ClearGadgetItemList(#List)
AddGadgetItem(#List,-1,"BBB")
AddGadgetItem(#List,-1,"AAA")
Sort=PureLVSORT_GetSortingDirection(#List)
If Sort=0
PureLVSORT_SortListIconNow(#List,0,-1)
Else
PureLVSORT_SortListIconNow(#List,0,1)
EndIf
EndProcedure
OpenWindow(0,100,100,230,100,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Pure_LVSort Test")
CreateGadgetList(WindowID())
ListIconGadget(#List,5,5,100,90,"Name",95)
ButtonGadget(#Button,120,5,100,90,"Refresh")
PureLVSORT_SelectGadgetToSort(#List,#PureLVSORT_ShowClickedHeader_IconRight)
AddData()
PureLVSORT_SortListIconNow(#List,0,1)
Repeat
EventID = WaitWindowEvent()
If EventID=#PB_Event_Gadget And EventGadgetID()=#Button
AddData()
EndIf
Until EventID = #PB_Event_CloseWindow
Code: Select all
;/ PureLVSort 4.0 Test
Enumeration
#List
#Button
EndEnumeration
Procedure AddData()
Static Sort ;/ Store Sort Direction
ClearGadgetItemList(#List)
AddGadgetItem(#List,-1,"BBB")
AddGadgetItem(#List,-1,"AAA")
;/ Here's the Sort of the List with Direction stored
Temp=PureLVSORT_GetSortingDirection(#List)
If Temp <> Sort : Sort=Temp : EndIf ;/ Sort change if Direction change
If Sort=0 : Sort=1 : EndIf ;/ Sort if first launch
PureLVSORT_ClearGadget(#List)
PureLVSORT_SelectGadgetToSort(#List,#PureLVSORT_ShowClickedHeader_IconRight)
PureLVSORT_SortListIconNow(#List,0,Sort)
EndProcedure
OpenWindow(0,100,100,230,100,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Pure_LVSort Test")
CreateGadgetList(WindowID())
ListIconGadget(#List,5,5,100,90,"Name",95)
ButtonGadget(#Button,120,5,100,90,"Refresh")
AddData()
Repeat
EventID = WaitWindowEvent()
If EventID=#PB_Event_Gadget And EventGadgetID()=#Button
AddData()
EndIf
Until EventID = #PB_Event_CloseWindow
I think I understand now. I will take a lookDroopy wrote:In the first code, the sort function works well the first time.
But after a content change (of the ListIcon) the sort function doesn't works.
Try the first code : When you clik the button, the list si not sorted
Code: Select all
Enumeration
#List
#Button
EndEnumeration
Procedure AddData()
ClearGadgetItemList(#List)
AddGadgetItem(#List,-1,"BBB" + Chr(10) + "1")
AddGadgetItem(#List,-1,"AAA" + Chr(10) + "3")
AddGadgetItem(#List,-1,"CCC" + Chr(10) + "2")
Sort = PureLVSORT_GetSortingDirection(#List)
If Sort=0
PureLVSORT_SortListIconNow(#List,0,-1)
Else
PureLVSORT_SortListIconNow(#List,0, 1)
EndIf
EndProcedure
OpenWindow(0,100,100,230,100,#PB_Window_SystemMenu|#PB_Window_ScreenCentered | #PB_Window_TitleBar ,"Pure_LVSort Test")
CreateGadgetList(WindowID())
ListIconGadget(#List,5,5,100,90,"A",50)
ButtonGadget(#Button,120,5,100,90,"Refresh")
AddGadgetColumn(#List, 1, "b", 50)
PureLVSORT_SelectGadgetToSort(#List,#PureLVSORT_ShowClickedHeader_IconRight)
AddData()
PureLVSORT_SortListIconNow(#List,0,1)
Repeat
EventID = WaitWindowEvent()
If EventID=#PB_Event_Gadget And EventGadgetID()=#Button
AddData()
EndIf
Until EventID = #PB_Event_CloseWindow
I have these results :Droopy wrote:No![]()
When the program is launched, the column 'A' is well sorted.
But when you click the Refresh button the column is not sorted !
Code: Select all
Enumeration
#List
#Button
EndEnumeration
Procedure AddData()
ClearGadgetItemList(#List)
AddGadgetItem(#List,-1,"BBB" + Chr(10) + "1")
AddGadgetItem(#List,-1,"AAA" + Chr(10) + "3")
AddGadgetItem(#List,-1,"CCC" + Chr(10) + "2")
Sort = PureLVSORT_GetSortingDirection(#List)
Debug Sort
If Sort=-1
PureLVSORT_SortListIconNow(#List,0,-1)
Else
PureLVSORT_SortListIconNow(#List,0, 1)
EndIf
EndProcedure
OpenWindow(0,100,100,230,100,#PB_Window_SystemMenu|#PB_Window_ScreenCentered | #PB_Window_TitleBar ,"Pure_LVSort Test")
CreateGadgetList(WindowID())
ListIconGadget(#List,5,5,100,90,"A",50)
ButtonGadget(#Button,120,5,100,90,"Refresh")
AddGadgetColumn(#List, 1, "b", 50)
PureLVSORT_SelectGadgetToSort(#List,#PureLVSORT_ShowClickedHeader_IconRight)
AddData()
PureLVSORT_SortListIconNow(#List,0,1)
Repeat
EventID = WaitWindowEvent()
If EventID=#PB_Event_Gadget And EventGadgetID()=#Button
AddData()
EndIf
Until EventID = #PB_Event_CloseWindow
This is not a bug, it's a feature : after a ClearGadgetItemList() call, PureLVSORT_GetSortingDirection() is set to 0, like it is after ListIconGadget() (you can't sort an empty list, so no sorting direction).Droopy wrote:I cant memorize the SortDirection because after a ClearGadgetItemList the function PureLVSORT_GetSortingDirection always return '0'
Code: Select all
;/ PureLVSort 4.0 Test
Enumeration
#List
#Button
EndEnumeration
Procedure AddData()
Static Sort ;/ Memorize Sort Direction
;/ Here I Store the Sort Direction ( Because ClearGadgetItem Delete Direction)
Temp=PureLVSORT_GetSortingDirection(#List)
If Temp<> 0 : Sort=Temp : EndIf
If Sort=0 : Sort=1 : EndIf ;/ Sort @ first launch
;/ Clearing ListIcon and Add Items
ClearGadgetItemList(#List)
AddGadgetItem(#List,-1,"BBB")
AddGadgetItem(#List,-1,"AAA")
AddGadgetItem(#List,-1,"CCC")
;/ Sort the ListIcon ( With Direction Memorized )
PureLVSORT_ClearGadget(#List)
PureLVSORT_SelectGadgetToSort(#List,#PureLVSORT_ShowClickedHeader_IconRight)
PureLVSORT_SortListIconNow(#List,0,Sort)
EndProcedure
OpenWindow(0,100,100,230,100,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Pure_LVSort 4.0 Test")
CreateGadgetList(WindowID())
ListIconGadget(#List,5,5,100,90,"Name",95)
ButtonGadget(#Button,120,5,100,90,"Refresh")
AddData()
Repeat
EventID = WaitWindowEvent()
If EventID=#PB_Event_Gadget And EventGadgetID()=#Button
AddData()
EndIf
Until EventID = #PB_Event_CloseWindow
Code: Select all
#Window_0 = 0
#ListIcon_0 = 0
;
Procedure Open_Window_0()
If OpenWindow(#Window_0, 216, 0, 602, 302, #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_SizeGadget, "PureLVSORT LastColumn AutoResize Test")
If CreateGadgetList(WindowID())
ListIconGadget(#ListIcon_0, 5, 5, 590, 285, "String", 110)
AddGadgetColumn(#ListIcon_0, 1, "Numeric", 110)
AddGadgetColumn(#ListIcon_0, 2, "Float", 110)
AddGadgetColumn(#ListIcon_0, 3, "DateDDMMYYYY", 120)
AddGadgetColumn(#ListIcon_0, 4, "DateMMDDYYYY", 120)
AddGadgetColumn(#ListIcon_0, 5, "FileSize", 120)
AddGadgetColumn(#ListIcon_0, 6, "NoSorting", 120)
AddGadgetItem(#ListIcon_0, -1, "ABCDE" + Chr(10) + "514" + Chr(10) + "0.9" + Chr(10) + "31/12/2004" + Chr(10) + "12/31/2004" + Chr(10) + "15.02 MB" + Chr(10) + "0")
AddGadgetItem(#ListIcon_0, -1, "ACDEF" + Chr(10) + "118" + Chr(10) + "1.9" + Chr(10) + "11/12/2004" + Chr(10) + "12/11/2004" + Chr(10) + "65 B" + Chr(10) + "1")
AddGadgetItem(#ListIcon_0, -1, "ZABCD" + Chr(10) + "-414" + Chr(10) + "7.0" + Chr(10) + "21/01/2003" + Chr(10) + "01/21/2003" + Chr(10) + "5.98 GB" + Chr(10) + "3")
AddGadgetItem(#ListIcon_0, -1, "DEFGH" + Chr(10) + "524" + Chr(10) + "900" + Chr(10) + "10/06/2001" + Chr(10) + "06/10/2001" + Chr(10) + "100 KB" + Chr(10) + "A")
EndIf
EndIf
EndProcedure
Open_Window_0()
; ListIcon Sort Setup
If PureLVSORT_SelectGadgetToSort(#ListIcon_0, #PureLVSORT_ShowClickedHeader_No) = #PureLVSORT_Ok
PureLVSORT_SetColumnType(#ListIcon_0, 0, #PureLVSORT_String) ; default, not necessary
PureLVSORT_SetColumnType(#ListIcon_0, 1, #PureLVSORT_Numeric)
PureLVSORT_SetColumnType(#ListIcon_0, 2, #PureLVSORT_Float)
PureLVSORT_SetColumnType(#ListIcon_0, 3, #PureLVSORT_DateDDMMYYYY)
PureLVSORT_SetColumnType(#ListIcon_0, 4, #PureLVSORT_DateMMDDYYYY)
PureLVSORT_SetColumnType(#ListIcon_0, 5, #PureLVSORT_FileSize)
PureLVSORT_SetColumnType(#ListIcon_0, 6, #PureLVSORT_NoSorting)
PureLVSORT_SetLastColumnAutoResize(#ListIcon_0, #True) ; <------ resize the window and compare #True / #False
EndIf
PureRESIZE_SetGadgetResize(#ListIcon_0, #True, #True, #True, #True)
;
Repeat
Event = WaitWindowEvent()
Until Event = #PB_EventCloseWindow
End