Remove all items from G4P Droplist

Hi, I’m trying to dynamically empty a drop list on certain conditions. I notice there is no “length” property for the droplist.

I don’t know how many items I will have, so when I try to use the “removeItem” method, it doesn’t work.

Any thoughts on how to totally empty a list so I can repopulate it with new values?

thanks,

Mike

The droplist control does not like to be empty. The best thing is not to empty the control but simply replace the existing items with a new set of items.

// dlst = a droplist control
// items = an array or list of Strings
// index = the index number for the selected item
dlst.setItems(items, index);
2 Likes

Thank you Peter, that works.

I was struggling with the .removeItem() command. It wasn’t working at all and I couldn’t figure out why. I needed to take a list of 4 things and make it a list of 2 things. Iterating over a randomly high number like 10 (won’t ever go above 10) to make sure I got rid of everything also just wasn’t working.

Not sure what happened, but now I am able to remove items, and just manipulate the first item to be the first item of the newly intended list, and of course your .addItem() works great.

Thank you kindly Peter; you always provide fabulous support.

all my best,

Mike