title: vb.net listbox search
body: <p>I'm trying to make <code>TextBox1</code> a search bar, to search for specific strings in <code>ListBox1</code>. </p>
  
  <p>I want it to remove other items that don't have the string I searched. For example, if a list contains (cheese, eggs, milk, chicken, chocolate) then searching for "ch" would only show cheese, chicken, and chocolate. Is this possible? </p>
  
  <p>This code I have here <em>WILL</em> search for the string, but doesn't eliminate others.</p>
  
  <p>EDIT: -These are all really great responses, but I can't use any of them because the listbox is being populated by filenames from a specific directory, which gives me this error;</p>
  
  <blockquote>
    <p>Items collection cannot be modified when the DataSource property is set.</p>
  </blockquote>
  
  <pre><code>Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
      Dim i As Integer = ListBox1.FindString(TextBox1.Text)
      ListBox1.SelectedIndex = i
      If TextBox1.Text = "" Then
          ListBox1.SelectedIndex = -1
      End If
  End Sub
  </code></pre>
  
  <p>I appreciate any help. Thanks.</p>