Page 1 of 1

Deleting listicon items

Posted: Sat Apr 22, 2006 3:10 am
by Matt
How would I delete all the items in a listicon gadget that are checked?

Re: Deleting listicon items

Posted: Sat Apr 22, 2006 3:38 am
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

Posted: Sat Apr 22, 2006 3:50 am
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)

Posted: Sat Apr 22, 2006 3:48 pm
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

Posted: Sat Apr 22, 2006 6:13 pm
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.

Posted: Sat Apr 22, 2006 7:35 pm
by H.Brill
oh sorry, i have not seen it.
in this case, i think, you must
delete the items manual.

Posted: Sat Apr 22, 2006 7:40 pm
by josku_x
did you even bother read the topic? Fangbeast made a simple but a very good solution..