Detecting ListIconGadget checkbox state
Posted: Wed May 18, 2005 6:45 am
Code updated for 5.20+
I just realised that checking for a value of #PB_ListIcon_Checked (which is 2)
with a ListIconGadget is not 100% reliable, because if the item is also selected,
then the return value is 3, not 2. You can check this by playing with the code
below. So, when you need to test the checkbox state of a ListIconGadget item,
make sure your test is whether the return value is >1, because:
0 = The item is unselected and unchecked.
1 = The item is selected.
2 = The item is checked.
3 = The item is checked and selected.
(@Fred: Maybe these values could go into the manual?).
I just realised that checking for a value of #PB_ListIcon_Checked (which is 2)
with a ListIconGadget is not 100% reliable, because if the item is also selected,
then the return value is 3, not 2. You can check this by playing with the code
below. So, when you need to test the checkbox state of a ListIconGadget item,
make sure your test is whether the return value is >1, because:
0 = The item is unselected and unchecked.
1 = The item is selected.
2 = The item is checked.
3 = The item is checked and selected.
(@Fred: Maybe these values could go into the manual?).
Code: Select all
If OpenWindow(0, 350, 250, 270, 150, "ListIconGadget", #PB_Window_SystemMenu)
ListIconGadget(0, 10, 10, 250, 115, "test", 200, #PB_ListIcon_CheckBoxes)
For r =1 To 5 : AddGadgetItem(0, -1, "Item #" + Str(r)) : Next
ButtonGadget(1, 10, 130, 200, 20," Click here to see all checkbox states")
Repeat
event = WaitWindowEvent()
If event = #PB_Event_Gadget And EventGadget() = 1
a$ = ""
For r = 1 To 5
item = GetGadgetState(0)
a$ + "Item #" + Str(r - 1) + " = " + Str(GetGadgetItemState(0, r-1)) + Chr(13)
Next
MessageRequester("test", a$)
EndIf
Until event = #PB_Event_CloseWindow
EndIf