Help regarding multiline textbox
-
Hi, I am using following line of code in a for loop to populate a multiline textbox.
this.textBox2.Text = this.textBox2.Text + '\n' +oCompResult.Errors[i].ErrorText.Trim();
I need to show each array item in separate line.But it doesnt happens even if there is a '\n' present. Pls help. -
Hi, I am using following line of code in a for loop to populate a multiline textbox.
this.textBox2.Text = this.textBox2.Text + '\n' +oCompResult.Errors[i].ErrorText.Trim();
I need to show each array item in separate line.But it doesnt happens even if there is a '\n' present. Pls help.try:
textBox2.Text += Environment.NewLine + oCompResult.Errors[i].ErrorText.Trim();
You'd be better off using a StringBuilder for this and setting the textBox2.Text after the loop. Simple example below...string[] sArray = { "a", "b", "c" };
StringBuilder sBuilder = new StringBuilder();
foreach (string thisString in sArray)
{
sBuilder.AppendLine(thisString);
}
textBox2.Text = sBuilder.ToString();Dave
modified on Monday, February 25, 2008 8:18 AM
-
Hi, I am using following line of code in a for loop to populate a multiline textbox.
this.textBox2.Text = this.textBox2.Text + '\n' +oCompResult.Errors[i].ErrorText.Trim();
I need to show each array item in separate line.But it doesnt happens even if there is a '\n' present. Pls help.since your output is line oriented, you should consider a ListBox instead of a TextBox; it does not need the concatenation of all strings, just a simple
this.ListBox1.Items.Add(oCompResult.Errors[i].ErrorText.Trim());
would do it for whatever number of lines you have, without a quadratic performance hit. :)Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.
-
since your output is line oriented, you should consider a ListBox instead of a TextBox; it does not need the concatenation of all strings, just a simple
this.ListBox1.Items.Add(oCompResult.Errors[i].ErrorText.Trim());
would do it for whatever number of lines you have, without a quadratic performance hit. :)Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.
thanks for help. Luc, if I use list view, it will lead to flicker problems on resizing so I cant use that.
-
thanks for help. Luc, if I use list view, it will lead to flicker problems on resizing so I cant use that.
I suggested a ListBox, not a ListView. I don't recall having seen any flickering ListBoxes yet. :)
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.