Code: Select all
EnableExplicit
Declare onLIGCallback()
define NrWin = OpenWindow(#PB_Any, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
if NrWin
global NrLIG = ListIconGadget(#PB_Any, 10, 10, 620,380, "Column 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect|#PB_ListIcon_ThreeState)
define c
define r
For c = 1 To 6
AddGadgetColumn(NrLIG, c, "Column " + Str(c), 100)
Next
For r = 0 To 1000
AddGadgetItem(NrLIG, r, " Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
SetGadgetItemData(NrLIG, r, #PB_ListIcon_Inbetween)
SetGadgetItemState(NrLIG, r, #PB_ListIcon_Inbetween)
Next
endif
BindGadgetEvent(NrLIG, @onLIGCallback())
Repeat
define NrWindowEvent = WaitWindowEvent()
if NrWindowEvent=#PB_Event_CloseWindow
break
endif
forever
Procedure onLIGCallback()
Protected NrGadget = EventGadget()
Protected NrEvenType = EventType()
Protected i
Protected WasChecked
Protected IsChecked
if GadgetType(NrGadget)=#PB_GadgetType_ListIcon
for i = 0 to CountGadgetItems(NrGadget)
WasChecked = GetGadgetItemData(NrGadget, i)
IsChecked= GetGadgetItemState(NrGadget, i)
if IsChecked<>WasChecked
debug "Checkbox row " + Str(i) + " changed from " + Str(WasChecked) + " to " + str(IsChecked)
SetGadgetItemData(NrGadget, i, IsChecked)
endif
next i
endif
EndProcedure ; onLIGCallback()
With 10000 rows it gets slow and laptop gets a little noisier...
Choosing an array to store the state could be faster.
The window callback solutions are always very smart; but when You check the states it's easier to change the handling to not check each change (pressing save button or similar). Callbacks look always clever in a small example organisation gets harder and using global variables...