Place your code in the Keypress event. When user presses Enter after typing in the text, it will be deleted from the listbox. The Do loop will also delete all items following the one the user typed.
Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim sel As Integer
If e.KeyChar = Chr(13) Then
sel = ListBox1.FindString(TextBox1.Text)
For x As Integer = sel To ListBox1.Items.Count - 1
ListBox1.Items.RemoveAt(sel)
Next
TextBox1.Clear()
TextBox1.Focus()
End If
End Sub
If you prefer to use a button, then just leave out the If and End If lines.
Bookmarks