Damian
Damian

Reputation: 39

Add the same string from textbox in two lines listbox?

Is it possible to add the same string typed in the texbox in the two lines of the listbox, as shown in the image below?

enter image description here

private void metroButton10_Click(object sender, EventArgs e)
    {
        listBox2.Items.Add("Next station: " + metroTextBox1.Text);
        listBox2.Items.Add(Environment.NewLine)
        metroTextBox1.Clear();
        listBox2.SelectedIndex = 0;
    }

Upvotes: 1

Views: 75

Answers (2)

gofret
gofret

Reputation: 19

Sure you can add same string typed in the textbox in the two lines of the listbox as;

private void button1_Click(object sender, EventArgs e)
    {
        listBox1.Items.Add("NextStation: " + textBox1.Text);
        listBox1.Items.Add("Station: " +textBox1.Text);
    }

ss after the button hit

Upvotes: 2

Sumon Tito
Sumon Tito

Reputation: 105

Use the following code.

 private void button1_Click(object sender, EventArgs e)
    {
        listBox1.Items.Add("Next Station: "+textBox1.Text);
        listBox1.Items.Add("Station: " + textBox1.Text);
    }

You Can't use new line. Because listbox can contain one item in a line.

Upvotes: 2

Related Questions