RobberBaron Posted December 18, 2010 Share Posted December 18, 2010 I am trying to use the lines in a TextBox to copy the line index data to another textbox. My problem is, whenever I try to append text to the second textbox, I get an IndexOutOfRangeException (Index was outside the bounds of the array). Is there some way to append text, regardless of line position? Here is the code I am using: private void textBox2_TextChanged(object sender, EventArgs e){ for (int _ = 0; _ < textBox2.Lines.Length; _++) { textBox1.Lines.SetValue(_.ToString(), _); };} Link to comment Share on other sites More sharing options...
Farhadm Posted December 18, 2010 Share Posted December 18, 2010 Try it : string[] lines = TextBox2.Text.Split('\n'); for (int i = 0; i < lines.Length; i++) { TextBox1.Text += i.ToString() + '\n'; } Link to comment Share on other sites More sharing options...
RobberBaron Posted December 18, 2010 Author Share Posted December 18, 2010 Won't that just append to the text? I'm just trying it...EDIT: Yeah, that only seems to be adding 0 on to the end of the text every time a key is pressed... Link to comment Share on other sites More sharing options...
Farhadm Posted December 19, 2010 Share Posted December 19, 2010 Please send your project files to me, I corret it Link to comment Share on other sites More sharing options...
RobberBaron Posted December 20, 2010 Author Share Posted December 20, 2010 I don't want to add the numbers onto the end of the first TextBox, I want to update so that for every line in TextBox2, the corresponding line in TextBox1 will hold the line number. Link to comment Share on other sites More sharing options...
Farhadm Posted December 20, 2010 Share Posted December 20, 2010 This code clear textbox then update : string[] lines = TextBox2.Text.Split('\n');TextBox2.Text="";for (int i = 0; i < lines.Length; i++){TextBox1.Text += i.ToString() + '\n';} Link to comment Share on other sites More sharing options...
RobberBaron Posted December 20, 2010 Author Share Posted December 20, 2010 Thanks, it almost works, but for some reason it won't register the newline. Wasn't there someway to get the newline character from Environment?EDIT: Oh yeah, Environment.NewLine. Thanks, work perfectly (although it is a bit slow at updating) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.