Detecting Checkbox state on ListIcon in pb5.1x x64

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4799
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Detecting Checkbox state on ListIcon in pb5.1x x64

Post 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
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Detecting Checkbox state on ListIcon in pb5.1x x64

Post 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.
BERESHEIT
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4799
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Detecting Checkbox state on ListIcon in pb5.1x x64

Post 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!!
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5027
Joined: Sun Apr 12, 2009 6:27 am

Re: Detecting Checkbox state on ListIcon in pb5.1x x64

Post 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


Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4799
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Detecting Checkbox state on ListIcon in pb5.1x x64

Post 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....
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: Detecting Checkbox state on ListIcon in pb5.1x x64

Post 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.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Detecting Checkbox state on ListIcon in pb5.1x x64

Post 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.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5027
Joined: Sun Apr 12, 2009 6:27 am

Re: Detecting Checkbox state on ListIcon in pb5.1x x64

Post 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

Egypt my love
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Detecting Checkbox state on ListIcon in pb5.1x x64

Post 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.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5027
Joined: Sun Apr 12, 2009 6:27 am

Re: Detecting Checkbox state on ListIcon in pb5.1x x64

Post 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
Egypt my love
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Detecting Checkbox state on ListIcon in pb5.1x x64

Post by Thunder93 »

That's a good workaround. :)
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Post Reply