title: clear listbox items except for searched items vb.net
body: <p>I am using the below code to find all the items in a listbox using vb.net 2005. But how can remove the non searched items from the listbox after searching?</p>
  
  <p>EDIT : I  included the entire code</p>
  
  <pre><code> Imports System.IO
  
  Public Class Form1
      Public Sub New()
  
           InitializeComponent()
          ListBox1.SelectionMode = SelectionMode.MultiExtended
  
  
      End Sub
  
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
          Dim reader As StreamReader = New StreamReader("input.txt")
          Try
              Me.ListBox1.Items.Clear()
              Do
                  Me.ListBox1.Items.Add(reader.ReadLine)
              Loop Until reader.Peek = -1
  
          Catch
              Me.ListBox1.Items.Add("File is empty")
  
          Finally
              reader.Close()
          End Try
      End Sub
  
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          ListBox1.BeginUpdate()
          ListBox1.SelectedIndices.Clear()
          If TextBox1.Text.Length &gt; 0 Then
              For index As Integer = 0 To ListBox1.Items.Count - 1
                  Dim item As String = ListBox1.Items(index).ToString()
  
                  If item.IndexOf(TextBox1.Text, StringComparison.CurrentCultureIgnoreCase) &gt;= 0 Then
  
                      ListBox1.SelectedIndices.Add(index)
                  End If
              Next
          End If
          ListBox1.EndUpdate()
      End Sub
  
      Private Sub ListBox1_DragEnter(ByVal sender As Object, ByVal e As  _
   System.Windows.Forms.DragEventArgs) Handles ListBox1.DragEnter
          If e.Data.GetDataPresent(DataFormats.FileDrop) Then
              e.Effect = DragDropEffects.All
          End If
      End Sub
  
      Private Sub ListBox1_DragDrop(ByVal sender As Object, ByVal e As  _
      System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop
          If e.Data.GetDataPresent(DataFormats.FileDrop) Then
              Dim MyFiles() As String
  
              Me.ListBox1.Items.Clear()
  
              MyFiles = e.Data.GetData(DataFormats.FileDrop)
              Using sr As StreamReader = New StreamReader(MyFiles(0))
                  Dim line As String
  
                  Do
                      line = sr.ReadLine()
  
                      ListBox1.Items.Add(line)
                  Loop Until line Is Nothing
  
              End Using
  
          End If
      End Sub
  End Class
  </code></pre>