I am trying to filter a ListBox based on the presence of a string. Basically, if there is a ListItem that doesn\'t contain the string then I want to remove all ListItems that do
Try reversing your loop, i.e. start from the end of the list. That way, deleting items won't shift the index of the remaining items you still have to check (which is the cause of your out of range exception).
The first way causes a problem because you're modifying the list while iterating over it. And that is, as you said, a big no-no.