Thanks Zapman, as I stated in my initial post, I went down the rabbit hole and used a List to buffer the data for the gadget (attached demo code shamelessly copied from Zapman's code and uses his Sortable ListIcon:
By the way, the real application reads data from several Windows servers to display in the ListIcon. Being able to filter "on the fly" is a god-send when you're trying to quickly find one piece of information amongst potentially hundreds of rows. The demo only filters on the first column, but you get the idea...
Code: Select all
EnableExplicit
XIncludeFile "ColumnSortedListIconGadget.pbi"
Define Timer0
Define Filter0$
Define Event
Define FilterLen
Structure RowElement
Col0.s
Col1.s
Col2.s
Col3.s
Col4.s
Col5.s
Col6.s
Filtered.b ; Visible (0) Or Hidden (1)?
EndStructure
Global NewList ListIconData.RowElement() ; use a List as opposed to an Arry because all the sorting
; is handled by Zapman's code - thanks again, Zapman!
Procedure Resort(GagdetID)
Protected LastColumn, LastAscentDescent
LastColumn = GetLastSortingColumn(GagdetID)
LastAscentDescent = GetLastSortingAscentDescent(GagdetID)
SortListIcon(GagdetID, LastColumn, LastAscentDescent)
EndProcedure
Procedure ResetFilteredField()
ForEach ListIconData()
ListIconData()\Filtered = #False
Next
EndProcedure
Procedure FilterGadget(Col, Str$)
; Filter List field based on Col
Protected Field$
ForEach ListIconData()
Select Col
Case 0
Field$ = ListIconData()\Col0
Case 1
Field$ = ListIconData()\Col1
Case 2
Field$ = ListIconData()\Col2
Case 3
Field$ = ListIconData()\Col3
Case 4
Field$ = ListIconData()\Col4
Case 5
Field$ = ListIconData()\Col5
Case 6
Field$ = ListIconData()\Col6
EndSelect
If FindString(Field$, Str$, 1, #PB_String_NoCase)
ListIconData()\Filtered = #False
Else
ListIconData()\Filtered = #True
EndIf
Next
EndProcedure
Procedure UpdateListIcon(GagdetID)
; Populate ListIcon taking Filtered field into account
Protected Line$
ClearGadgetItems(GagdetID)
ForEach ListIconData()
If ListIconData()\Filtered
Continue
EndIf
Line$ = ListIconData()\Col0 + Chr(10)
Line$ + ListIconData()\Col1 + Chr(10)
Line$ + ListIconData()\Col2 + Chr(10)
Line$ + ListIconData()\Col3 + Chr(10)
Line$ + ListIconData()\Col4 + Chr(10)
Line$ + ListIconData()\Col5 + Chr(10)
Line$ + ListIconData()\Col6 + Chr(10)
AddGadgetItem(GagdetID, - 1, Line$)
Next
Resort(GagdetID)
EndProcedure
Define HWindow = OpenWindow(#PB_Any, 0, 0, 550, 320, "Sortable ListIconGadget demo", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
;
Global ListIconGagdet = ListIconGadget(#PB_Any, 0, 30, WindowWidth(HWindow), 225, "", 0, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
Define Filter0 = EditorGadget(#PB_Any, 0, 5, 70, 20)
;
AddGadgetColumn(ListIconGagdet, 0, "Alpha", 70)
SetGadgetItemAttribute(ListIconGagdet, 0, #PB_ListIcon_ColumnAlignment, #PB_ListIcon_Center, 0)
AddGadgetColumn(ListIconGagdet, 1, "Integer", 70)
AddGadgetColumn(ListIconGagdet, 2, "Decimal", 80)
AddGadgetColumn(ListIconGagdet, 3, "Hexa", 80)
AddGadgetColumn(ListIconGagdet, 4, "Dates", 80)
AddGadgetColumn(ListIconGagdet, 5, "Hours", 80)
AddGadgetColumn(ListIconGagdet, 6, "Sporty", 80)
SetGadgetItemAttribute(ListIconGagdet, 0, #PB_ListIcon_ColumnAlignment, #PB_ListIcon_Center, 6)
;
Define ct
For ct = 1 To 5
SetGadgetItemAttribute(ListIconGagdet, 0, #PB_ListIcon_ColumnAlignment, #PB_ListIcon_Right, ct)
Next
;
Define mDate.q = Date()
Define AlphaList$ = "élève,devant,front,Absent,Column,Final,tirant,global,$,"
Define HourList$ = "12:30:20,12:30:00,12:30,18:10,6:00 PM,11:00 AM,9:45:15,8:45,16h30mn,"
Define SportyTimeList$ = "30'',5'20'',1'14''80''',1'14,5'80''',20'',10'50'',4'40''30''',90'''"
For ct = 1 To 9
AddElement(ListIconData())
ListIconData()\Col0 = StringField(AlphaList$, ct, ",")
ListIconData()\Col1 = Str(Random($FFFF))
ListIconData()\Col2 = StrF(Random($FFFFFF)/10000, 3)
ListIconData()\Col3 = "$" + RSet(Hex(Random($7FFFFFFF)), 8, "0")
ListIconData()\Col4 = FormatDate(CSLI_DateFormat$, mDate)
mDate + 100000
ListIconData()\Col5 = StringField(HourList$, ct, ",")
ListIconData()\Col6 = StringField(SportyTimeList$, ct, ",")
ListIconData()\Filtered = 0 ; 0 = visible
Next
UpdateListIcon(ListIconGagdet) ; populate gadget from List data
;
Define NotSortableOption = OptionGadget(#PB_Any, 15, WindowHeight(HWindow) - 50, 140, 22, "Reset to not sortable")
Define DontShowArrowsOption = OptionGadget(#PB_Any, 190, WindowHeight(HWindow) - 50, 150, 22, "Sortable with no arrows")
Define ShowLeftArrowsOption = OptionGadget(#PB_Any, 375, WindowHeight(HWindow) - 50, 150, 22, "Sortable with left arrows")
Define ShowTopArrowsOption = OptionGadget(#PB_Any, 15, WindowHeight(HWindow) - 30, 400, 22, "Sortable with top arrows (when clicked) - (XP compatible)")
SetGadgetState(ShowLeftArrowsOption, 1)
:
;
MakeListIconSortable(ListIconGagdet, #CSLI_LeftArrows) ; <-- This is the only line you need to make the gadget sortable.
;
; But you can also decide to sort the gadget by default from one column content:
SortListIcon(ListIconGagdet, 0, #CSLI_Ascent)
;
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Timer
Select EventTimer()
Case Timer0
Debug "Timer0 triggered, time to apply Filter0"
RemoveWindowTimer(HWindow, Timer0)
Filter0$ = GetGadgetText(Filter0)
FilterGadget(0, Filter0$)
UpdateListIcon(ListIconGagdet)
EndSelect
EndIf
If Event = #PB_Event_Gadget
Select EventGadget()
Case Filter0
If EventType() = #PB_EventType_Change
Filter0$ = GetGadgetText(Filter0)
Debug "Filter0 changed!" + Filter0$
If Len(Filter0$) = 0
; filter field cleared, reset Filtered field(s) to all be visible
ResetFilteredField()
UpdateListIcon(ListIconGagdet)
RemoveWindowTimer(HWindow, Timer0)
Else
RemoveWindowTimer(HWindow, Timer0) ; reset timer
AddWindowTimer(HWindow, Timer0, 1000)
EndIf
EndIf
Case NotSortableOption
MakeListIconSortable(ListIconGagdet, #CSLI_NotSortable)
Case DontShowArrowsOption
MakeListIconSortable(ListIconGagdet, #CSLI_NoArrow)
Case ShowLeftArrowsOption
MakeListIconSortable(ListIconGagdet, #CSLI_LeftArrows)
Case ShowTopArrowsOption
MakeListIconSortable(ListIconGagdet, #CSLI_TopArrows)
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow