How to insert text into a textbox from a string to a file in multiple textboxes?

I'm trying to do something, but I didn't find anything on google since I don't know how to do it to get the correct results.

I have a form with 9 TextBox controls and a PlainText file with 9 lines of text.

I want to click a button which will then add the first line of text from the text file to the first text block, then the second line to the second text box, etc. Can anyone please give any advice on how to do this?

+2


source to share


1 answer


Try the following:

using (StreamReader reader = File.OpenText("yourFileName.txt"))
{
    textBox1.Text = reader.ReadLine();
    textBox2.Text = reader.ReadLine();
    textBox3.Text = reader.ReadLine();
    textBox4.Text = reader.ReadLine();
    textBox5.Text = reader.ReadLine();
    textBox6.Text = reader.ReadLine();
    textBox7.Text = reader.ReadLine();
    textBox8.Text = reader.ReadLine();
    textBox9.Text = reader.ReadLine();
}

      



edit: changed solution to use File.OpenText

insteadFileStream

+9


source







All Articles