Displaying MultiLine Content in a TextBox

Z

zacks

I am developing a C#.NET application in VS2005 that needs a function
that allows the user to edit some text content stored in a Text column
in a database. I have a TextBox control with AcceptsReturn, AcceptsTab
and MultiLine properties all set to True.

When I set the Text property of the control to the string returned
from the database and show the form, the content in the textbox isn't
"formatted". All newlines appear as a funky undisplayable character
and does not cause the content following it to appear on the next
line. I dumped the content returned from the database to the Command
window, and it definitely has "\r"'s all through it.

How do I get the text content to appear the same as it would if loaded
into, say, a Notepad window?
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,
When I set the Text property of the control to the string returned
from the database and show the form, the content in the textbox isn't
"formatted". All newlines appear as a funky undisplayable character
and does not cause the content following it to appear on the next
line. I dumped the content returned from the database to the Command
window, and it definitely has "\r"'s all through it.

In windows you need \r\n at the end. How the text is stored int he DB in the
first place?
Can you post the code you are using to read it from the DB and assign it to
the textbox?

You could replace \r for Environment.NewLine this will assure you to use
the correct new line format.
 
Z

zacks

Hi,


In windows you need \r\n at the end. How the text is stored int he DB in the
first place?
Can you post the code you are using to read it from the DB and assign it to
the textbox?

You could replace \r for Environment.NewLine this will assure you to use
the correct new line format.

I posted my question before fully investigating this. You are exactly
on the money. The content that was not being displayed correctly had
been imported with only "\r" at the end of each line. I am coming from
VB.NET and am still learning about the differences in the way things
worked.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

I posted my question before fully investigating this. You are exactly
on the money. The content that was not being displayed correctly had
been imported with only "\r" at the end of each line. I am coming from
VB.NET and am still learning about the differences in the way things
worked.


so do as I suggested you, replace \r for Environment.NewLine
 
C

Chris Dunaway

I am developing a C#.NET application in VS2005 that needs a function
that allows the user to edit some text content stored in a Text column
in a database. I have a TextBox control with AcceptsReturn, AcceptsTab
and MultiLine properties all set to True.

When I set the Text property of the control to the string returned
from the database and show the form, the content in the textbox isn't
"formatted". All newlines appear as a funky undisplayable character
and does not cause the content following it to appear on the next
line. I dumped the content returned from the database to the Command
window, and it definitely has "\r"'s all through it.

How do I get the text content to appear the same as it would if loaded
into, say, a Notepad window?

Be sure that the TextBox's MultiLine property is set to true.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top