Page 1 of 1

Detecting change in checkbox of ListIconGadget

Posted: Sun Mar 08, 2020 11:06 am
by marcoagpinto
Hello!

How do I detect if a checkbox in a listicongadget has been changed without scanning the whole listicongadget?

Image

Thanks!

Re: Detecting change in checkbox of ListIconGadget

Posted: Sun Mar 08, 2020 11:56 am
by Demivec
Maybe by checking the events, gadget state and item state. :wink:

Code: Select all

Define b, event, eg, item

If OpenWindow(0, 0, 0, 700, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    TextGadget    (7,  10, 105, 330, 20, "ListIcon with Checkbox", #PB_Text_Center)
    ListIconGadget(1,  10, 120, 330, 70, "Column 1", 100, #PB_ListIcon_CheckBoxes)  ; ListIcon with checkbox

      For b = 2 To 4          ; add 3 more columns to listicon
        AddGadgetColumn(1, b, "Column " + Str(b), 65)
      Next
      For b = 0 To 2          ; add 4 items to each line of the listicon
        AddGadgetItem(1, b, "Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4")
      Next

      Repeat 
        event = WaitWindowEvent()
        If event = #PB_Event_Gadget

          eg = EventGadget()
          If eg = 1 And EventType() = #PB_EventType_Change
            item = GetGadgetState(1)
            If item <> -1
              If GetGadgetItemState(1, item) & #PB_ListIcon_Checked
                Debug "item #" + item + " is currently selected and checked"
              Else
                Debug "item #" + item + " is currently selected and unchecked"
              EndIf
            EndIf
            
          EndIf
        EndIf
        
      Until event = #PB_Event_CloseWindow
  EndIf

Re: Detecting change in checkbox of ListIconGadget

Posted: Sun Mar 08, 2020 1:00 pm
by marcoagpinto
@Demivec

Hello!

That part of having the line selected I had already reached days ago.

What I really meant is to just click on the checkboxes without selecting an item.

Is it possible?

Thanks!

Re: Detecting change in checkbox of ListIconGadget

Posted: Sun Mar 08, 2020 1:10 pm
by BarryG
marcoagpinto wrote:What I really meant is to just click on the checkboxes without selecting an item.
By Rashad here (but you still need to loop all items) -> viewtopic.php?p=405811#p405811

Re: Detecting change in checkbox of ListIconGadget

Posted: Sun Mar 08, 2020 1:23 pm
by marcoagpinto
@BarryG

Thanks!

I was afraid it had to be done that way, but now it is officially the only way.

Re: Detecting change in checkbox of ListIconGadget

Posted: Sun Mar 08, 2020 2:12 pm
by RASHAD
Hi
It will be much easier with using Windows API

Because BarryG has pointed to me ,so next is another solution to check the changing of CheckBox status instantaneous
Of course you have to be careful with the ListIcon row height :wink:
You can get any item checkbox status from the ARRAY at any time

This snippet need more to do for the items not shown yet (be tuned)

Code: Select all

Global Dim checkstate(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

gadgetx = GadgetX(1,#PB_Gadget_ScreenCoordinate)
gadgety = GadgetY(1,#PB_Gadget_ScreenCoordinate) 

AddWindowTimer(0,125,10)
Repeat
  Select WaitWindowEvent(1)
     
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_SizeWindow ,#PB_Event_MoveWindow
        gadgetx = GadgetX(1,#PB_Gadget_ScreenCoordinate)
        gadgety = GadgetY(1,#PB_Gadget_ScreenCoordinate)     
     
    Case #PB_Event_Timer 
      If flag = 1
        checkx = DesktopMouseX()
        checky = DesktopMouseY()
        If checkx > gadgetx And checkx < (gadgetx+18)
           item = Int((checky - gadgety - 18)/18)
           itemstste = GetGadgetItemState(1,item)
           checkstate(item) = itemstste & #PB_ListIcon_Checked
           If checkstate(item) = 2
              count + 1
           Else
              count - 1
           EndIf
        EndIf
        If count <> oldcount
          Debug "Item : "+Str(item)+" Checkbox state changed "
        EndIf        
         oldcount = count
        flag = 0
      EndIf    
     
    Case #PB_Event_Gadget
      Select EventGadget()               
        Case 1
          Select EventType()                   
            Case #PB_EventType_LeftClick
              flag = 1
             
          EndSelect         
      EndSelect
  EndSelect
 
Until Quit = 1


Re: Detecting change in checkbox of ListIconGadget

Posted: Sun Mar 08, 2020 2:21 pm
by marcoagpinto
Thanks, guys!