Listicon checkboxes problem?

Just starting out? Need help? Post your questions and find answers here.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Listicon checkboxes problem?

Post by collectordave »

Hi all,


Running MAC Os Mojave 10.14.6 and PB 5.73 LTS

All I want to do is check/uncheck some selected list icon checkboxes from a selection.

I have got the checking Ok selecting more than one row in the list icon and clicking Select checks the checkboxes.

Trying to uncheck them gives me a problem.

Running the code select a few entries then click select and the checkboxes are selected.

Select the same ones again and click deselect and nothing happens!

Code: Select all

 
 
  If OpenWindow(0, 0, 0, 700, 300, "ListIconCheck", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

    ListIconGadget(1,  10, 20, 330, 200, "Column 1", 100, #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes|#PB_ListIcon_MultiSelect) 

    ButtonGadget(2,340,20,80,25,"Select")
    ButtonGadget(3,340,50,80,25,"Deselect")    
    
      For b = 2 To 4         
        AddGadgetColumn(1, b, "Column " + Str(b), 65)
      Next
      For b = 0 To 5   
        AddGadgetItem(1, b, "Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4")
      Next

    
    Repeat
        Event = WaitWindowEvent()

        Select EventGadget()
            
          Case 2
            
            If EventType() = #PB_EventType_LeftClick
            
              
              Debug "Select"
            
              For x = 0 To CountGadgetItems(1)
              
                Debug "Item " + Str(x)
              
                If GetGadgetItemState(1,x) = #PB_ListIcon_Selected

                  SetGadgetItemState(1,x, #PB_ListIcon_Checked)
 
               EndIf

              Next
                
            EndIf  
  
          Case 3
              
            If EventType() = #PB_EventType_LeftClick
              
              Debug "Unselect"
              For x = 0 To CountGadgetItems(1)
                  
                  If GetGadgetItemState(1,x) = #PB_ListIcon_Selected
                    
                    Debug "Item " + Str(x)
                    
                      SetGadgetItemState(1,x,0)

                  EndIf

                Next
                
             EndIf   
 
            EndSelect          
 
      Until Event = #PB_Event_CloseWindow
      
    EndIf
    
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Listicon checkboxes problem?

Post by collectordave »

Just been experimenting again.

Seems that the state of the item is a flag showing the what is happening.


Found you can define some constants:-

#ListIconNoSelect = 0 :Not selected and checkbox unchecked
#ListIconSelected = 1 :Item selected and checkbox unchecked
#listIconChecked = 2 :Item not selected and checkbox checked
#ListIconAll = 3 :Item selected and checkbox checked


The you can use:-

Code: Select all

                If GetGadgetItemState(1,x) & #ListIconSelected = #ListIconSelected         
              
                  Debug "Item " + Str(x) + " Selected"
                  
                EndIf
                
                 If GetGadgetItemState(1,x) & #listIconChecked = #listIconChecked        
              
                  Debug "Item " + Str(x) + " Checked"
                  
                EndIf
                
                
                
Which will tell you whether an Item is selected with or without the checkbox state.

You can also use these in SetGadgetItemstate() so you can set an item to be unselected, selected, unselected checkbox checked and Selected with the checkbox checked.

Hope this helps somebody!
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Post Reply