Deleting listicon items

Just starting out? Need help? Post your questions and find answers here.
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Deleting listicon items

Post by Matt »

How would I delete all the items in a listicon gadget that are checked?
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Deleting listicon items

Post by Fangbeast »

Matt wrote:How would I delete all the items in a listicon gadget that are checked?
NumItems CountGadgetItems(#MyListIcon) - 1

For DelItems = NumItems to 0 step -1
If GetGadgetItemState(#MyListIcon, DelItems) = #PB_ListIcon_Checked
; If GetGadgetItemState(#MyListIcon, DelItems) & #PB_ListIcon_Checked
RemoveGadgetItem(#MyListIcon, DelItems)
EndIf
Next DelItems

See how you go
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Post by Matt »

awesome thanks :)
I guess I wasn't thinking... to do the loop with a step -1... I was trying to many other ways without that... now I understand 8)
H.Brill
User
User
Posts: 12
Joined: Tue Sep 20, 2005 6:07 am

Post by H.Brill »

you can use API - Functions .

SendMessage_(GadgetID(MyGadget), 4105, 0, 0)

Code: Select all

; code for version 4.0 BETA

#MyWindow = 0
MyGadget.l
 If OpenWindow(#MyWindow,100,100,300,500,"ListIcon Beispiel", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
   If CreateGadgetList(WindowID(#MyWindow))
     ButtonGadget(1, 10, 10, 100, 20, "Delete all")
     MyGadget = ListIconGadget(#PB_Any,5,100,290,290,"Name",100,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
     AddGadgetColumn(MyGadget,1,"Adresse",250)
     AddGadgetItem(MyGadget,-1,"Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
     AddGadgetItem(MyGadget,-1,"Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
     Repeat
       EventID = WaitWindowEvent()
       If EventID = #PB_Event_Gadget
          Select EventGadget()
             Case 1
                  SendMessage_(GadgetID(MyGadget), 4105, 0, 0)
          EndSelect     
       EndIf   
     Until EventID = #PB_Event_CloseWindow
   EndIf
 EndIf
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

@h.brill: Your code sure works, but it removes all items not regarding if the checkbox of the item was checked or not.
H.Brill
User
User
Posts: 12
Joined: Tue Sep 20, 2005 6:07 am

Post by H.Brill »

oh sorry, i have not seen it.
in this case, i think, you must
delete the items manual.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

did you even bother read the topic? Fangbeast made a simple but a very good solution..
Post Reply