Hi,
I have a textbox and a listbox and I'd like to have the listbox add an item (based on textbox) when enter is pressed.
I am using vb 2008
Please help, I am struggling lol. Thanks!
Hi,
I have a textbox and a listbox and I'd like to have the listbox add an item (based on textbox) when enter is pressed.
I am using vb 2008
Please help, I am struggling lol. Thanks!
Just create a method like so:
void AddItemToListBox(string item)
{
lstMyList.Items.Add(item);
}
Then hook this up to the key down event of the text box for when the Enter key is pressed:
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
AddItemToListBox(textBox1.Text);
}
}