반응형
I have a text object in my crystal report, and i set the value programatically for it, using something like this:
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.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) + '") + "'";
원문 : http://tim.mackey.ie/CrystalReportsTextObjectIgnoresNewlineCarriageReturnRn.aspx
반응형