RemoveGadgetItem

Just starting out? Need help? Post your questions and find answers here.
Stefan
Posts: 160
Joined: Mon Feb 05, 2018 9:44 pm

RemoveGadgetItem

Post by Stefan »

I want to delete all Intems, but this code doesn't work.
I know "ClearGadgetItems()", but I want to know what I am doing wrong here.

Code: Select all

Enumeration
  #window
  #pic
  #ListIconGadget
EndEnumeration
OpenWindow(#window,0,0,800,600,"a Window")
CreateImage(#pic, 30,30,32,RGB(200,0,0))
ListIconGadget(#ListIconGadget,10,10,200,200,"Listicongadget",100,#PB_ListIcon_CheckBoxes)
For i=1 To 10
 AddGadgetItem(#ListIconGadget, -1, "Pic "+Str(i),ImageID(#pic))  
Next i
c=CountGadgetItems(#ListIconGadget)
Debug c
For j=0 To c-1 
   RemoveGadgetItem(#ListIconGadget,j)
Next j
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

Re: RemoveGadgetItem

Post by the.weavster »

Code: Select all

For j=0 To c-1 
  ;RemoveGadgetItem(#ListIconGadget,j) ; <--- not this
  RemoveGadgetItem(#ListIconGadget, 0) ; <--- this
Next j
Because if you start at the top of the list each time you remove a line all the other lines' index changes
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: RemoveGadgetItem

Post by Peter »

... or this way:

Code: Select all

For j = c-1 To 0 Step -1
  RemoveGadgetItem(#ListIconGadget,j)
Next j
Stefan
Posts: 160
Joined: Mon Feb 05, 2018 9:44 pm

Re: RemoveGadgetItem

Post by Stefan »

Merci :)
Post Reply