[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

textbox: add text to listbox when the enter key is pressed

Posted on 2008-06-19
3
Medium Priority
?
366 Views
Last Modified: 2012-06-21
Hi,

I have a reasonably easy question but can't seem to get it right:

I have a textbox in my form (textBox1), when the enter key is pressed it should enter the text in the textbox in a listbox(listBox1)

How can i make it enter the text in the listbox (once for every enter pressed)?
0
Comment
Question by:Sjaaksken
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
Bruce_1975 earned 300 total points
ID: 21824700
You can use the KeyUp event of the textbox.

Regards,
Bruce
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
    // check the key and just act if return (or enter) was pressed
    if (e.KeyCode == Keys.Return)
    {
        listBox1.Items.Add(textBox1.Text);
        // clear the text box or just comment out the next line 
        textBox1.Clear();
    }
}

Open in new window

0
 

Author Comment

by:Sjaaksken
ID: 21824856
Hi, thanks for the reply,

apparently I was close but when I did paste your solution and ran the program it didn't enter the text when the enter key was pressed. I tried assigning other keys to the 'if' statement but same result.

Am I forgetting something? It also doesn't clear the textbox as it doesnt seem to accept the enter action
0
 
LVL 6

Expert Comment

by:Bruce_1975
ID: 21826362
I think you solved the problem. If you still have problems, just let me know.

Regards,
Bruce
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question