none
Add listbox the value in text box when clicked enter RRS feed

  • Question

  • Hi,

    I have a textbox and I want to write in it when when I click enter I want that the thing that I wrote adds to listbox.

    How can I do it?

    Atakan 
    Monday, December 8, 2008 12:40 PM

Answers

  • Ok i have your answer,


    First:

    Select your textBox then on the right hand side you obviously see your properties above it slightly you will see a yellow lighting bolt press that and look for the KeyPress event double click it and a code block will appear in this area type,


    {
            if (e.KeyChar == (char)Keys.Enter)
           {
                listBox1.Items.Add(textBox1.Text);
           }
               
    }


    Hope that helps,
    Remember if this answered your question select "mark as answer" above ^___^

     

    • Proposed as answer by sillybob Monday, December 8, 2008 1:58 PM
    • Marked as answer by AtakanSever Monday, December 8, 2008 2:00 PM
    Monday, December 8, 2008 1:56 PM

All replies

  • on the button click add the following:

        listBox1.Items.Add(textBox1.Text);

    I hope is this what you are looking for.....!
    prs
    Monday, December 8, 2008 12:54 PM
  • Thanks but it is for button. What I want is after I write in textbox I click enter and it goes to listbox.

    Atakan 
    Monday, December 8, 2008 1:20 PM
  • Hello AtakanSever,

    If you are new to get to the button click,

    Double click the "Enter" button you made and the code editor will appear in between these "{}" you write your code listBox1.Items.Add(textBox1.Text);

    I hope that helps

    @Your most recent reply;

    I dont understand your question what that code above will do is all the text you have in your textbox will be added to your listBox when the button is pressed.

    This i thought is what you wanted correct?


    Regards

    Silly
    Monday, December 8, 2008 1:22 PM
  • Thanks for your info. I already answered for that. I know how to do it with button but I don't want to use button. That is the problem. I want that after I write in textbox one click enter in keybord and it goes to listbox.

    Atakan
    Monday, December 8, 2008 1:27 PM
  • oh ok i see,

    i will just have a look and get back to you.
    Monday, December 8, 2008 1:30 PM
  • this is what you want???

    private void mytextbox_KeyDown(object sender, keyevent e)
    {
      if(e.KeyCode == Keys.Enter)
      {
         mylistbox.Items.Add(mytextbox.Text);
         mytextbox.Clear();
      }
    }


    prs
    Monday, December 8, 2008 1:48 PM
  • I think it must be something like that. I will try and let you now. But not soon as I'm fighting with my project.

    Thanks.

    Atakan
    Monday, December 8, 2008 1:52 PM
  • Ok i have your answer,


    First:

    Select your textBox then on the right hand side you obviously see your properties above it slightly you will see a yellow lighting bolt press that and look for the KeyPress event double click it and a code block will appear in this area type,


    {
            if (e.KeyChar == (char)Keys.Enter)
           {
                listBox1.Items.Add(textBox1.Text);
           }
               
    }


    Hope that helps,
    Remember if this answered your question select "mark as answer" above ^___^

     

    • Proposed as answer by sillybob Monday, December 8, 2008 1:58 PM
    • Marked as answer by AtakanSever Monday, December 8, 2008 2:00 PM
    Monday, December 8, 2008 1:56 PM
  • That is it. 

    Thanks...

    Atakan
    Monday, December 8, 2008 2:00 PM