Page 1 of 1
Detecting Checkbox state on ListIcon in pb5.1x x64
Posted: Sun Feb 24, 2013 3:32 am
by Fangbeast
I haven't used checkboxes before and am confused by conflicting results. Don't even know if I am doing it right.
Which event should I be using to detect the checkbox change?
Should I be able to check which line fired it without using API?
The event below fires 0 for check and uncheck so I am confused to say the least.
Code: Select all
If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(1, 10, 10, 620,380, "Column 1", 100, #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes)
For b = 2 To 6
AddGadgetColumn(1, b, "Column " + Str(b), 100)
Next
For b = 0 To 30
AddGadgetItem(1, b, "Item 1" + Chr(10) + "Item 2" + Chr(10) + "Item 3" + Chr(10) + "Item 4")
Next
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Select EventType()
Case #PB_EventType_LeftClick
CurrentLine.i = GetGadgetState(1)
CurrentState.i = GetGadgetItemState(1, CurrentLine.i) & #PB_ListIcon_Checked
If CurrentState.i = #PB_ListIcon_Checked
Debug "Item checked"
ElseIf CurrentState.i <> #PB_ListIcon_Checked
Debug "Item not checked"
EndIf
EndSelect
EndSelect
EndSelect
Until Quit = 1
EndIf
End
Re: Detecting Checkbox state on ListIcon in pb5.1x x64
Posted: Sun Feb 24, 2013 4:37 am
by netmaestro
It actually looks like a bug to me. When you leftbuttondown on a checkbox you get a leftclick event and then when you leftbuttonup you get another one. Imho you should only get one on leftbuttonup. The reason your test isn't working is that clicking a checkbox doesn't change the selected item (I don't know if that's the intended behavior or not). In the case of your test, there is no selected item and so you always get a not-checked answer because you're using GetGadgetState. If you first select an item and then play with its checkbox you should see your desired answers. But- two at a time, which surely can't be intended.
I don't know how the coder is supposed to know which item just got checked or unchecked if it doesn't change the state. Keeping an array of tested checks in a loop would be unwieldy at best.
Re: Detecting Checkbox state on ListIcon in pb5.1x x64
Posted: Sun Feb 24, 2013 5:14 am
by Fangbeast
Okay, that pretty much answer it for me. It seems to have been the state (pun intended) for a long time with checkboxes and listicongadgets and I didn't want to overcomplicate the issue so I will get rid of checkboxes and use normal selections instead.
Back to the drawing board!!
Re: Detecting Checkbox state on ListIcon in pb5.1x x64
Posted: Sun Feb 24, 2013 8:15 am
by RASHAD
No API
Should be Cross platform
Code: Select all
Global Dim state(100)
If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(1, 10, 10, 620,380, "Column 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect)
For c = 1 To 6
AddGadgetColumn(1, c, "Column " + Str(c), 100)
Next
For r = 0 To 100
AddGadgetItem(1, r, " Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
Next
EndIf
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Select EventType()
Case #PB_EventType_Change
For x = 0 To 100
If GetGadgetItemState(1,x) <> state(x)
state(x) = GetGadgetItemState(1,x)
Break
EndIf
Next
For x = 0 To 100
If state(x) > 1
Debug "Item : "+Str(x)+" Checked"
EndIf
Next
Debug "*****"
EndSelect
EndSelect
EndSelect
Until Quit = 1
Re: Detecting Checkbox state on ListIcon in pb5.1x x64
Posted: Sun Feb 24, 2013 8:40 am
by Fangbeast
Thanks RASHAD but i've given up the idea in favour of a simpler solution and released another new version of RecipeMuncher to help out avid cooks.
Just a few more import formats that I am asking someone's help with and then I can have a rest.
Not sure if the download links at box.com is correct but then nobody has complained so....
Re: Detecting Checkbox state on ListIcon in pb5.1x x64
Posted: Sun Feb 24, 2013 3:42 pm
by SFSxOI
Yeah, this "two state" response from the checkbox in listicon drove me nuts recently. Got one event with checked and then a second event with unchecked when what I really needed was just to know if it was checked and did not care about the unchecked state> I expected to be able to just test if it was checked or not at the time of test.
Re: Detecting Checkbox state on ListIcon in pb5.1x x64
Posted: Sun Feb 24, 2013 4:18 pm
by Thunder93
netmaestro wrote:It actually looks like a bug to me. When you leftbuttondown on a checkbox you get a leftclick event and then when you leftbuttonup you get another one.
When clicking on the checkbox or the line, it shouldn't at any giving time produce two hits over #PB_EventType_LeftClick. PB at some point is becoming confused and then registering leftbuttondown.
Re: Detecting Checkbox state on ListIcon in pb5.1x x64
Posted: Sun Feb 24, 2013 4:28 pm
by RASHAD
Now it gives the status of the check box & the item itself
No repeated action
And it is very fast
Deleted unneeded code
Code: Select all
If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(1, 10, 10, 620,380, "Column 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect)
For c = 1 To 6
AddGadgetColumn(1, c, "Column " + Str(c), 100)
Next
For r = 0 To 1000
AddGadgetItem(1, r, " Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
Next
EndIf
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Select EventType()
Case #PB_EventType_Change
For x = 0 To CountGadgetItems(1)
If GetGadgetItemState(1,x) = 1
Debug "Item : "+Str(x)+" Selected"
ElseIf GetGadgetItemState(1,x) = 2
Debug "Item : "+Str(x)+" Checked"
ElseIf GetGadgetItemState(1,x) = 3
Debug "Item : "+Str(x)+" Selected & Checked"
EndIf
Next
Debug "*****"
EndSelect
EndSelect
EndSelect
Until Quit = 1
Re: Detecting Checkbox state on ListIcon in pb5.1x x64
Posted: Sun Feb 24, 2013 5:00 pm
by Thunder93
When I click directly on the very first checkbox and then click on the 6th checkbox down.
Item : 0 Checked
*****
Item : 0 Checked
Item : 6 Checked
*****
I would in most cases only want to giving the latest change.
Re: Detecting Checkbox state on ListIcon in pb5.1x x64
Posted: Sun Feb 24, 2013 5:13 pm
by RASHAD
Code: Select all
Global Dim state(100)
If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(1, 10, 10, 620,380, "Column 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect)
For c = 1 To 6
AddGadgetColumn(1, c, "Column " + Str(c), 100)
Next
For r = 0 To 100
AddGadgetItem(1, r, " Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
Next
EndIf
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Select EventType()
Case #PB_EventType_Change
For x = 0 To 100
If GetGadgetItemState(1,x) <> state(x)
state(x) = GetGadgetItemState(1,x)
If state(x) > 1
Debug "Item : "+Str(x)+" Checked"
Else
Debug "Item : "+Str(x)+" UnChecked"
EndIf
Break
EndIf
Next
Debug "*****"
EndSelect
EndSelect
EndSelect
Until Quit = 1
Re: Detecting Checkbox state on ListIcon in pb5.1x x64
Posted: Sun Feb 24, 2013 7:15 pm
by Thunder93
That's a good workaround.
