# Wednesday, January 25, 2006
Wednesday, January 25, 2006 1:52:05 PM (GMT Standard Time, UTC+00:00) ( .Net General | .Net Windows Forms | Asp.Net )
I have a text object in my crystal report, and i set the value programatically for it, using something like this:
(rpt.Section3.ReportObjects["txtDate"] as TextObject).Text = DateTime.Now.ToShortDateString();
this works fine, until you put a string with line breaks inside it, specifically \r\n or the carriage return character.  This is a bug in CR for .Net, you can read the official blurb here.  the work-around code they post is in VB, and it made no sense to me when i read it.
what they actually do is make you change the TextObject into a FormulaField (you have to view the 'Field Explorer' tab next to the toolbox, and drag on a Formula Field).  Then you set 'CanGrow' to true, and then you go back to your code, and do the most arcane work-around i've ever seen.  you set the formula to your text string, but you must surround it in single quote characters, and replace \r\n with some inline managed code as follows: ' + chr(10) + '
when i first read this, i thought they had made a syntax error, but this is the way to do it, and it works.  the new format for setting the formula field is:
rpt.DataDefinition.FormulaFields[0].Text = "'" + YourString.Replace("\r\n", "' + chr(10) + '") + "'";

Comments [11] | | # 
Thursday, August 03, 2006 12:55:19 PM (GMT Daylight Time, UTC+01:00)
OMG, thanks a load!

I've just came across this problem a few hours ago, and have been trying to solve it since. You really helped me out with this one. Though I should have solved it myself, looking at the solution.

Nevertheless, you saved me a few hours!

Thursday, March 15, 2007 2:01:31 PM (GMT Standard Time, UTC+00:00)
Hi
It works !
These really helped me.
Jude
Monday, June 18, 2007 3:52:50 PM (GMT Daylight Time, UTC+01:00)
Hello
I need to place html tags in the FormulaFields. I face the problem of having
'>' changes to &gt; and '<' changes to &lt;

I tried the mentioned code. but did not work at all.

Please help me.

Thanks a lot in advance.

Virendra


Tuesday, April 08, 2008 10:24:06 AM (GMT Daylight Time, UTC+01:00)
i need a newline to output, chr(10), helped me thanks.
salman
Monday, September 29, 2008 4:53:28 PM (GMT Daylight Time, UTC+01:00)
Thanks a ton duuuuuude (hurley style)....trying since a couple of days now. Many offered solns but none worked, but this.



Rocky
Saturday, October 04, 2008 8:59:31 AM (GMT Daylight Time, UTC+01:00)
Ei thanks for the post. Big help.
Bong
Tuesday, January 05, 2010 2:32:17 PM (GMT Standard Time, UTC+00:00)
Thanks, you saved my day :) It took me quite a few hours to find your solution idea.
Tuesday, March 02, 2010 11:58:36 AM (GMT Standard Time, UTC+00:00)
Tim, thank you very much for posting this, saved the day!! :)

I'll link to here from my Blog later today.
Thursday, March 04, 2010 10:49:22 AM (GMT Standard Time, UTC+00:00)
Thanks a lottttttttttttt :)
pankti
Wednesday, July 07, 2010 11:28:40 AM (GMT Daylight Time, UTC+01:00)
Thanks.

This problem has been niggling me for days.

I find it hard to believe that forcing a newline has to be done this way!
Andrew
Friday, August 06, 2010 1:35:26 PM (GMT Daylight Time, UTC+01:00)
Another way: if you can, put the field as HTML text. Then, in your string, use "<br>". Worked fine here!
String.Concat("Tempo de Trabalho: ", ddlTempoDeTrabalho.SelectedItem.Text, "<br>");
Rafael Meneses da Silva
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview