By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,889 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,889 IT Pros & Developers. It's quick & easy.

Multiline Textbox

P: n/a
Hi all,

I'm trying to add lines to a multiline textbox. Here's what I'd like to end
up with in the textbox (as an example):

Line1
Line2
Line3

I've tried a couple of methods but nothing seems to be working. Code like
this doesn't work:

s = "Line1";
TextBox1.Text += s + "\n";
s = "Line2";
TextBox1.Text += s + "\n";
s = "Line3";
TextBox1.Text += s + "\n";

I end up with:

Line1[]Line2[]Line3[]

(Where [] is presumably some funky representation of the character '\n').

I also tried to assign values to the lines as we go

TextBox1.Lines[0].Text = "Line1";
TextBox1.Lines[1].Text = "Line2";
TextBox1.Lines[2].Text = "Line3";

I get "Index Outside the Bounds of the Array."

I'm missing something simple here I'm sure. Any ideas?

Thanks,
Michael C.
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In article <6X*********************@news4.srv.hcvlny.cv.net >,
mi******************************@getridofthis.com says...
Hi all,

I'm trying to add lines to a multiline textbox. Here's what I'd like to end
up with in the textbox (as an example):

Line1
Line2
Line3

I've tried a couple of methods but nothing seems to be working. Code like
this doesn't work:

s = "Line1";
TextBox1.Text += s + "\n";
s = "Line2";
TextBox1.Text += s + "\n";
s = "Line3";
TextBox1.Text += s + "\n";

I end up with:

Line1[]Line2[]Line3[]

(Where [] is presumably some funky representation of the character '\n').

I also tried to assign values to the lines as we go

TextBox1.Lines[0].Text = "Line1";
TextBox1.Lines[1].Text = "Line2";
TextBox1.Lines[2].Text = "Line3";

I get "Index Outside the Bounds of the Array."

I'm missing something simple here I'm sure. Any ideas?

Thanks,
Michael C.


I seem to remember that there is a Multiline property for textboxes.
Have you tried setting that to true?
Nov 16 '05 #2

P: n/a
Hi Micheal C,

Remember to set the textbox multiline setting to true.

3 ways of coding it.

1)

textBox1.Text = "Euro 2004 Football" + Environment.NewLine + "World Cup 2006";

2)

string str1 = "Superman";
string str2 = "Spiderman";

textBox1.Text = str1 + "\r\n" + str2;

3)

string[] strArray = new string[5];
strArray[0] = "Line 1";
strArray[1] = "Line 2";
strArray[2] = "Line 3";
strArray[3] = "Line 4";
strArray[4] = "Line 5";

textBox1.Lines = strArray;

Hope it helps. Cheers.
--
Regards,
Chua Wen Ching :)
"Pollux" wrote:
In article <6X*********************@news4.srv.hcvlny.cv.net >,
mi******************************@getridofthis.com says...
Hi all,

I'm trying to add lines to a multiline textbox. Here's what I'd like to end
up with in the textbox (as an example):

Line1
Line2
Line3

I've tried a couple of methods but nothing seems to be working. Code like
this doesn't work:

s = "Line1";
TextBox1.Text += s + "\n";
s = "Line2";
TextBox1.Text += s + "\n";
s = "Line3";
TextBox1.Text += s + "\n";

I end up with:

Line1[]Line2[]Line3[]

(Where [] is presumably some funky representation of the character '\n').

I also tried to assign values to the lines as we go

TextBox1.Lines[0].Text = "Line1";
TextBox1.Lines[1].Text = "Line2";
TextBox1.Lines[2].Text = "Line3";

I get "Index Outside the Bounds of the Array."

I'm missing something simple here I'm sure. Any ideas?

Thanks,
Michael C.


I seem to remember that there is a Multiline property for textboxes.
Have you tried setting that to true?

Nov 16 '05 #3

P: n/a
Yes, I set the multiline property to true. Third option won't work -- the
items are being added dynamically on the fly. The "\r\n" code worked.
Thanks!

Michael C.

"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message
news:F0**********************************@microsof t.com...
Hi Micheal C,

Remember to set the textbox multiline setting to true.

3 ways of coding it.

1)

textBox1.Text = "Euro 2004 Football" + Environment.NewLine + "World Cup 2006";
2)

string str1 = "Superman";
string str2 = "Spiderman";

textBox1.Text = str1 + "\r\n" + str2;

3)

string[] strArray = new string[5];
strArray[0] = "Line 1";
strArray[1] = "Line 2";
strArray[2] = "Line 3";
strArray[3] = "Line 4";
strArray[4] = "Line 5";

textBox1.Lines = strArray;

Hope it helps. Cheers.
--
Regards,
Chua Wen Ching :)
"Pollux" wrote:
In article <6X*********************@news4.srv.hcvlny.cv.net >,
mi******************************@getridofthis.com says...
Hi all,

I'm trying to add lines to a multiline textbox. Here's what I'd like to end up with in the textbox (as an example):

Line1
Line2
Line3

I've tried a couple of methods but nothing seems to be working. Code like this doesn't work:

s = "Line1";
TextBox1.Text += s + "\n";
s = "Line2";
TextBox1.Text += s + "\n";
s = "Line3";
TextBox1.Text += s + "\n";

I end up with:

Line1[]Line2[]Line3[]

(Where [] is presumably some funky representation of the character '\n').
I also tried to assign values to the lines as we go

TextBox1.Lines[0].Text = "Line1";
TextBox1.Lines[1].Text = "Line2";
TextBox1.Lines[2].Text = "Line3";

I get "Index Outside the Bounds of the Array."

I'm missing something simple here I'm sure. Any ideas?

Thanks,
Michael C.


I seem to remember that there is a Multiline property for textboxes.
Have you tried setting that to true?

Nov 16 '05 #4

P: n/a
Hi Micheal C,

All of the 3 solutions works fine in my PC. Maybe some type error when i type it here. Haha!

Happy that you get it working now! :)
--
Regards,
Chua Wen Ching :)
"Michael C" wrote:
Yes, I set the multiline property to true. Third option won't work -- the
items are being added dynamically on the fly. The "\r\n" code worked.
Thanks!

Michael C.

"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message
news:F0**********************************@microsof t.com...
Hi Micheal C,

Remember to set the textbox multiline setting to true.

3 ways of coding it.

1)

textBox1.Text = "Euro 2004 Football" + Environment.NewLine + "World Cup

2006";

2)

string str1 = "Superman";
string str2 = "Spiderman";

textBox1.Text = str1 + "\r\n" + str2;

3)

string[] strArray = new string[5];
strArray[0] = "Line 1";
strArray[1] = "Line 2";
strArray[2] = "Line 3";
strArray[3] = "Line 4";
strArray[4] = "Line 5";

textBox1.Lines = strArray;

Hope it helps. Cheers.
--
Regards,
Chua Wen Ching :)
"Pollux" wrote:
In article <6X*********************@news4.srv.hcvlny.cv.net >,
mi******************************@getridofthis.com says...
> Hi all,
>
> I'm trying to add lines to a multiline textbox. Here's what I'd like to end > up with in the textbox (as an example):
>
> Line1
> Line2
> Line3
>
> I've tried a couple of methods but nothing seems to be working. Code like > this doesn't work:
>
> s = "Line1";
> TextBox1.Text += s + "\n";
> s = "Line2";
> TextBox1.Text += s + "\n";
> s = "Line3";
> TextBox1.Text += s + "\n";
>
> I end up with:
>
> Line1[]Line2[]Line3[]
>
> (Where [] is presumably some funky representation of the character '\n'). >
> I also tried to assign values to the lines as we go
>
> TextBox1.Lines[0].Text = "Line1";
> TextBox1.Lines[1].Text = "Line2";
> TextBox1.Lines[2].Text = "Line3";
>
> I get "Index Outside the Bounds of the Array."
>
> I'm missing something simple here I'm sure. Any ideas?
>
> Thanks,
> Michael C.
>
>
>

I seem to remember that there is a Multiline property for textboxes.
Have you tried setting that to true?


Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.