
PureLVSORT library : sorting ListIconGadgets (and more)
Moderator: gnozal
I need to sort a Listicon (Works).
The content of the ListIcon can change, after a change i want to sort the content.( Doesn't works)
I also want to memorize the SortDirection ( +1 / -1 )
Here's my buggy code :
The content of the ListIcon can change, after a change i want to sort the content.( Doesn't works)
I also want to memorize the SortDirection ( +1 / -1 )
Here's my buggy code :
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
I find a way to fix this :
But is there a simple way ?
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
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
@Droopy : I don't understand ?
The PureLVSORT_GetSortingDirection() function gets the last sorting direction, even if you have cleared the listicon in between, i.e. it is not cleared after a ClearGadgetItemList() call.
Is this your problem ?
I could set the sorting direction to zero after a ClearGadgetItemList() call.
The PureLVSORT_GetSortingDirection() function gets the last sorting direction, even if you have cleared the listicon in between, i.e. it is not cleared after a ClearGadgetItemList() call.
Is this your problem ?
I could set the sorting direction to zero after a ClearGadgetItemList() call.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
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
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Update
Changes :
- Special Droopy fix
@ Droopy : this code seems to work like you expected ?
Changes :
- Special Droopy fix
@ Droopy : this code seems to work like you expected ?
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
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
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 !
> Launch :
column A
AAA
BBB
CCC
The column is sorted [+1], because
AddData() --> Sort=0 --> PureLVSORT_SortListIconNow(#List,0,-1)
PureLVSORT_SortListIconNow(#List,0,1)
> Refresh :
column A
CCC
BBB
AAA
The column is sorted [-1], because
AddData() --> Sort=0 --> PureLVSORT_SortListIconNow(#List,0,-1)
What is wrong ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Thanks Gnozal, the sort is fixed.
But stay the problem to store the SortDirection.
Here's the code to show my problem. (Launch in Degug mode)
I cant memorize the SortDirection because after a ClearGadgetItemList the function PureLVSORT_GetSortingDirection always return '0'
But stay the problem to store the SortDirection.
Here's the code to show my problem. (Launch in Degug mode)
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
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
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'
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Here's my fixed code
Thanks again
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
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Update
Changes :
- new function PureLVSORT_SetLastColumnAutoResize() : resize the last column when the ListIcon is resized.
Changes :
- new function PureLVSORT_SetLastColumnAutoResize() : resize the last column when the ListIcon is resized.
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
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).