How would I make it so that if I select an item in ListBox1 and I press the "Delete" key then it will be removed?
Printable View
How would I make it so that if I select an item in ListBox1 and I press the "Delete" key then it will be removed?
You'd handle the key down event, and delete the selected item.
Came up with this,
Sorry for not trying anything before asking a question.Code:Private Sub ListBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown
If e.KeyCode = Keys.Delete AndAlso ListBox1.SelectedItem <> Nothing Then
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End If
End Sub
I think since I have access to getting a quick answer I should ask before experimenting by myself... I really need to stop doing that.