maxrpg

hi,

im trying to figure out how to read the contents of a richtextbox Line by Line and place each line into a texbox...for example:

place line 1 of richtextbox into textbox1

place line 2 of richtextbox into textbox2

place line 3 of richtextbox into textbox3

....and so on

ive looked all over and havent found anything to help me on this..im really stuck can someone help me please

im writing in C#



Re: Windows Forms General read richtextbox line by line..place into textboxs?

Ðãv? S. Â???????

One way you could do it (if your text box controls are named textbox1, textbox2, textbox3, and so on) is to use a loop.

for (int i = 0; i <= richTextBox1.Lines.Count; i++)
{
string textbox = string.Format("textbox{0}", i);
Controls[ textbox ].Text = richTextBox1.Lines[ i ];
}





Re: Windows Forms General read richtextbox line by line..place into textboxs?

maxrpg

hi,

when i try this code i get an error "Error 1 'System.Array' does not contain a definition for 'Count' "

my textboxes are setup like you said..labled as textbox1..textbox2 and so on

thanks





Re: Windows Forms General read richtextbox line by line..place into textboxs?

Ðãv? S. Â???????

Yeah, my bad, replace 'Count' with 'Length'.





Re: Windows Forms General read richtextbox line by line..place into textboxs?

maxrpg

hi

thanks for the reply, that fixed that error but now im getting another one lol

"Index was outside the bounds of the array."

im not sure why its not working, i have a simple form with 1 richtextbox and 5 textboxes on it. ive placed a button on the form which once clicked activates your code. ill place the code here:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO;

namespace WindowsApplication18

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

for (int i = 0; i <= richTextBox1.Lines.Length;i++ )

{

string textBox = string.Format("textBox{0}", i);

Controls[textBox].Text = richTextBox1.LinesIdea;

}

}

}

}

have i done something wrong

thank you so much for your help.





Re: Windows Forms General read richtextbox line by line..place into textboxs?

Ðãv? S. Â???????

Use this:

for (int i = 0; i <= richTextBox1.Lines.Length - 1; i++)
{
string textBox = string.Format("textBox{0}", i + 1);
Controls[textBox].Text = richTextBox1.Lines[ i ];
}




Re: Windows Forms General read richtextbox line by line..place into textboxs?

maxrpg

hi

Excellent that work perfectly Smile

your a real treasure thanks so much for all your help

nice one Smile