.Net ramblings
# Wednesday, 25 January 2006
Crystal Reports TextObject ignores newline, carriage return, \r\n
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) + '") + "'";

Wednesday, 25 January 2006 13:52:05 (GMT Standard Time, UTC+00:00)  #    Comments [16]  .Net General | .Net Windows Forms | Asp.Net

Thursday, 03 August 2006 12:55:19 (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, 15 March 2007 14:01:31 (GMT Standard Time, UTC+00:00)
It works !
These really helped me.
Monday, 18 June 2007 15:52:50 (GMT Daylight Time, UTC+01:00)
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.


Tuesday, 08 April 2008 10:24:06 (GMT Daylight Time, UTC+01:00)
i need a newline to output, chr(10), helped me thanks.
Monday, 29 September 2008 16:53:28 (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.

Saturday, 04 October 2008 08:59:31 (GMT Daylight Time, UTC+01:00)
Ei thanks for the post. Big help.
Tuesday, 05 January 2010 14:32:17 (GMT Standard Time, UTC+00:00)
Thanks, you saved my day :) It took me quite a few hours to find your solution idea.
Tuesday, 02 March 2010 11:58:36 (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, 04 March 2010 10:49:22 (GMT Standard Time, UTC+00:00)
Thanks a lottttttttttttt :)
Wednesday, 07 July 2010 11:28:40 (GMT Daylight Time, UTC+01:00)

This problem has been niggling me for days.

I find it hard to believe that forcing a newline has to be done this way!
Friday, 06 August 2010 13:35:26 (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
Thursday, 30 December 2010 18:43:57 (GMT Standard Time, UTC+00:00)
Works fine.

Many thanks to you (and Google).
Andy Jacobs
Sunday, 23 January 2011 16:56:05 (GMT Standard Time, UTC+00:00)
I have been searching for a solution to this problem for along time
Thank you very much
Monday, 04 July 2011 10:11:18 (GMT Daylight Time, UTC+01:00)
Thanks a lot dude! Like!
Cabine Swine
Thursday, 26 January 2012 18:01:29 (GMT Standard Time, UTC+00:00)
This helped me SO MUCH! Thank you :D
Craig Frost
Thursday, 01 March 2012 20:27:48 (GMT Standard Time, UTC+00:00)
Thanks dude. That really helped.
Please login with either your OpenID above, or your details below.
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview