title: How to remove selected items from a listbox
body: <p>This is for a VB.NET 4.5 project in VS2015 Community.</p>
  
  <p>I am trying to remove certain selected items from a listbox, but only if the selected item meets a condition. I've found plenty of examples on how to remove selected items. But nothing that works with a condition nested in the loop going through the selected items (at least, I can't get the examples to work with what I'm trying to do...)</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    Dim somecondition As Boolean = True
      Dim folder As String
      For i As Integer = 0 To lstBoxFoldersBackingUp.SelectedItems.Count - 1
  
          If somecondition = True Then
              folder = lstBoxFoldersBackingUp.SelectedItems.Item(i)
              Console.WriteLine("folder: " &amp; folder)
              lstBoxFoldersBackingUp.SelectedItems.Remove(lstBoxFoldersBackingUp.SelectedItems.Item(i))
          End If
      Next
  </code></pre>
  
  <p>The console output correctly shows the text for the current iteration's item, but I can't get the Remove() to work. As the code is now, I get the console output, but the listbox doesn't change.</p>