locked
Adding a new line on a click event for c#

    Question

  • I am trying to build a application that shows data in a multiline textbox.  The user picks items from the comboboxes and clicks the button, the information that was picked now shows up in the box.  What I am trying to do is have it display as a list of items everytime someone clicks the button but, the only thing I get is that the information gets overwritten with the new items when the button is clicked.
    This is how I would like this to look:

    Johnson Green Bay
    Thomas Miami
    Cutler Denver

    But, if i choose the first set of items from the comboboxes everything is ok.  When I choose "Thomas Miami" from the comboboxes and click go it erases the "Johnson Green Bay" and writes "Thomas Miami" over where Johnson was.  I have been trying for about 6 hours with many different ways to try to make this happen and I just want it to appear like the above example.  Any thoughts on this would be great.

    Thanks.
    Tuesday, September 04, 2007 3:48 AM

Answers

  • So from the sounds of it you've got a line that looks something like this firing off in your event handler...

     

    Code Snippet
    textBox1.Text = listBox1.SelectedItem.ToString();

     

     

    Instead, try something like this where instead of overwriting what is there, we add our text and a new line each time:

     

    Code Snippet

    textBox1.Text += listBox1.SelectedItem.ToString() + Environment.NewLine;

     

     

    Tuesday, September 04, 2007 3:56 AM
  • That worked perfectly!  I just had to modify the code that you gave me slightly.  Thank you very much!


    Tuesday, September 04, 2007 4:03 AM

All replies

  • So from the sounds of it you've got a line that looks something like this firing off in your event handler...

     

    Code Snippet
    textBox1.Text = listBox1.SelectedItem.ToString();

     

     

    Instead, try something like this where instead of overwriting what is there, we add our text and a new line each time:

     

    Code Snippet

    textBox1.Text += listBox1.SelectedItem.ToString() + Environment.NewLine;

     

     

    Tuesday, September 04, 2007 3:56 AM
  • That worked perfectly!  I just had to modify the code that you gave me slightly.  Thank you very much!


    Tuesday, September 04, 2007 4:03 AM