Clearing a listview control not happening

I'm attempting to clear a listview of all items but some are lingering.

The list contains 5 items, when below snippet is run, 2 items remain in the list. The count property contains the correct value.

for (var i=0; i<lstView.count; i++)
	lstView.RemoveItem(i);

If you delete item 0, item 1 moves up to become item 0, item 2 moves up to become item 1, and so on. You either need to delete the items in reverse, or just delete item 0 every time, or (the simplest) use -1 to delete them all at once.

You can either change RemoveItem(i) to RemoveItem(0) which will iteratively remove the first item of whatever remains in the list, or dispense with the loop altogether and RemoveItem(-1) to get rid of all items at once. Per the help...

You can also specify -1 to completely clear the contents of the control, removing all items at once.

@Jon beat me to it! :slight_smile:

Wow, I should have caught that, sorry to waste your time. It's late here time for bed...

Thanks