Remove Items from ComboBox at run time

mac-duff

Member
Joined
Dec 21, 2009
Messages
24
Programming Experience
Beginner
Hi,

I found this in the internet to add values to a combobox:
VB.NET:
  Private Sub ComboBox_Matricula_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox_Matricula.KeyPress
        If e.KeyChar = Chr(Keys.Enter) Then
            ComboBox_Matricula.Items.Add(ComboBox_Matricula.Text)
            ComboBox_Matricula.Text = Nothing
        End If
    End Sub

but the question is now, how can I remove this by marking/ touching with mouse one value and click on the keyboard "del"?

Thx
Stephan
 
VB.NET:
Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
        If e.KeyCode = Keys.Delete Then
            ComboBox1.Items.Remove(CType(sender, ComboBox).SelectedItem)
        End If
    End Sub

I hope this helps :)
 
Back
Top