How to Add New Items to the List when Enter Key is Pressed

9 Dec 20191 minute to read

To add the new items which are entered by the user at runtime after the user had pressed the enter key, we need to catch the KeyDown event.

private voiddomainUpDownExt1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
// Add new items when user press the Enter key.
    if(!domainUpDownExt1.Items.Contains ( domainUpDownExt1.Text )) domainUpDownExt1.Items.Add(domainUpDownExt1.Text);
Private SubdomainUpDownExt1_KeyDown(ByValsenderAs Object,ByValeAsSystem.Windows.Forms.KeyEventArgs)

' Add new items when user press the Enter key.
Ife.KeyCode = Keys.EnterThen
If NotdomainUpDownExt1.Items.Contains(domainUpDownExt1.Text)Then
End If
End If
End Sub