0
private void button2_Click(object sender, EventArgs e)
{
     string[] lines = System.IO.File.ReadAllLines(this.textBox2.Text);
     foreach (string line in lines)
     {
          this.listProxy.Items.Add(lines);
     }
}

When I click the button it is not writing it out to the ListBox.

How can I make it add each line in order to the ListBox?

0

2 Answers 2

5

Your should use line instead lines

this.listProxy.Items.Add(line);

look the code edited below:

private void button2_Click(object sender, EventArgs e)
{
    string[] lines = System.IO.File.ReadAllLines(this.textBox2.Text);
    foreach (string line in lines)
    {
        this.listProxy.Items.Add(line);
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

If this is for a System.Windows.Forms.ListBox you could skip the foreach and use listProxy.Items.AddRange(lines);
0

First, for whta i see in the code provided you are getting text from textbox and not from a TextFile.

Second, make sure that the TextFile you are going to use, contains information.

Third, you could use a try catch block in order to detect errors and be able to correct them before sending this to production.

1 Comment

It looks to me like he's getting the filename from the textbox

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.