locked
Crystal report fields spill-over - do not clip RRS feed

  • Question

  • User-1330070619 posted

    In the crystal reports, fields do not clip if they are over the specified length but rather continue to write over and you end-up seeing many fields on top of each other. But this behaviour is true only when you run the application. If you check the report preview during design time, it is shown correctly.

    Monday, May 12, 2008 3:13 AM

All replies

  • User2125237006 posted

    I had a problem with fields in Crystal Reports X where data driven textboxes would not grow to the right to accommodate the text length.  It would grow in Height and overlap a textbox that was placed directly below it.  It's important to note that the textboxes were both in the same section of the report (Details).  I solved this by splitting the section into Details a and Details b.  The sections would grow as the textbox grew and move the section below down, hence preventing the overlap.

    Thursday, June 12, 2008 1:02 PM
  • User-1330070619 posted

    If I have a seperate section, then there will be another line below it. This is not what I want. I want a single line to show all the details. The width I set is good enough to show enough details.

    One workround I found is to set the cangrow attribute to true and number of lines attribute to 1 (of the fieldobject). But this also produces slightly ugly report if the content cannot fit to the allocated width, the field's vertical alignment does not match with the rest of the items and becomes higher.

    Thursday, June 12, 2008 7:13 PM
  • User2125237006 posted

    Ok,  Let me see if I understand what you want.

     You have a control, I'm assuming a data driven textbox, that when it gets too large for the text box, you want to clip...or truncate?  It shows correctly in the Designer but when publishing, it's displaying wacky.  Text overlapping?   I'm not clear on what behavior you are witnessing here.  Is there more than one control that is overlapping?  Is it multiple records overlapping?  Is the text wrapping withing the textbox and it doesn't grow so you either see the tops of the next line or it repeats overtop itselff?

    If you are looking to simply truncate text to fit in the textbox, I would suggest creating a function to trim the datafield to a set number of characters that match your textbox width.  You could even create a hidden section that contained the entire text in a larger area so if they expanded the section they could read the entire record. 

    I've used Crystal Reports since 6.0 and I understand how buggy it can be.  What version are you using?  Is there any way  you can provide more information or a sample?  I may be able help if I can duplicate your issue.

     Also, what are you displaying the report in?  Is it the CrystalReportsViewer?  ActiveX component?  Java Component?  Crystal Reports Server? They all can have their own little quirks.

    Thursday, June 12, 2008 8:29 PM
  • User2125237006 posted

    I should also mention that you can set sections to "overlay". This way two separate sections can look like one.  It is usually used for graphics.

     Also, you can align all your textboxes to vertical align top so when your field grows, all your textboxes stay aligned.

    Thursday, June 12, 2008 8:38 PM
  • User-1330070619 posted

    tsttntice, 

    Ok, to make things a bit clearer, I have a report file (.rpt) and I have a CrystalReportViewer control, that shows the .rpt file. And my problems are with the CrystalReportViewer. If I export the report to pdf, the pdf file shows how it is ment to display but when you view the report on the web page, CrystalReportViewer stuffs things up.

    I am using Visual Studio 2005 Professional and there is no versioning mentioned for the Crystal Reports. It just says Crystal Reports for Visual Studio 2005. I believe it is almost the same version as X but not sure.

    I have side by side text fields (IFieldObject to be exact) in the section details section on a single line. The data to be displayed in some of these fields are longer than the width of these fileds. What I am expecting is the data to be clipped if the text is longer than the width of the textboxes. But instead, the entire text gets written, regarless of its length, over the next text boxes (IFieldObjects). One solution as you suggested is to trim the underlying text programmatically. But this solution also has some defficiencies if the font is not monospaced plus, to amount of work required to figure-out how many characters for each textbox width for various font sizes and properties (like bold, italic, etc) and the additional potential work in the future if you want to resize the text boxes.

    The CanGrow workaround I mentioned before also has defficiencies since it does not utilise the full length of the textbox if the underlying text has spaces as it tries to write the text by not dividing the words. Also, its vertical alignment changes as well. This workaround is more feasible If I can set the vertial alignments to top as you suggested but there is no property for vertial aligment. The workaround to the workaround is to set the heights of the textboxes to a very small size but If you do that, the pdf export gets screwed!

    I am sorry not providing any samples as the forum does not allow attachments but you can experiment by using CrystalReportViewer and long texts as underlying data for relatively narrow textboxes.

    Sunday, June 15, 2008 8:31 PM
  • User2125237006 posted

    Thanks for the info.  I'm trying to duplicate your results right now.  If you prefer, you can contact me directly at ttillotson@ttsos.com so we can exchange examples or screenshots.  Then, when we have a solution, we can post it back to the blog to close it out. 

     You are correct on how the versions of Crystal Reports are distributed.  The Crystal Reports for Visual Studio 2005 is its own version.  It is supported by Microsoft rather than BusinessObjects. I use the CrystalReportViewer 10.2 with the VS2005 version but haven't seen this issue.  I've also used Crystal Reports XI with the same control. (I know..., "Works on my machine." stupid comment) This just indicates that I haven't captured the exact configuration you have in order to duplicate the bug.  I'm using a sample VS2005 report.

     What is your datasource? SQL Server? version?   What is the database field type?

    Can you send the full control tag on your aspx page?  Example:

    <CR:CrystalReportViewer ID="crvDocumentViewer" runat="server" ..........

     Also the registry tag:

    <%@ Register Assembly="CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

     Have you tried the "Lock position and size" property in the Common tab for the field format properties?  (Just a wild try).   You can format the vertical alignment using a cascading style sheet and placing the CSS Class Name into the same Common tab.

     So far as you have mentioned, it works fine in the designer.  More to follow.

    Monday, June 16, 2008 8:58 AM
  • User2125237006 posted

    Here's another quick thing you can try.  Try setting the configuration of the report from the code side instead of in the Report Designer.  I'm getting a hunch that the format of the object may be getting overridden when you create your iFieldObject.  Honestly, I haven't used the IFieldObject through code before so I may be out of my league on your question. 

     This is the code behind a basic aspx web form.  Hopefully it may offer a little insight that may make more sense to you than it does to me right now.

    Option Strict On Option Explicit On

    Imports CrystalDecisions.CrystalReports.Engine

    Imports CrystalDecisions.Shared

     

    Imports SSTART

    Imports System.Collections

     

    Partial Class TestReport Inherits System.Web.UI.Page

    Private crReport As ReportDocument

    Private crPath As String

    Private Sub ConfigureCrystalReports()

    crPath = "reports/CanGrowReport.rpt"

    Dim reportpath As String = Server.MapPath(crPath)

    Dim ReportType As String = ""

    Dim ReportTypeCriteria As String = "CrystalDecisions.CrystalReports.Engine.FieldObject"

    Try

    crReport = New ReportDocument()

    crReport.Load(reportpath)

    crvDocumentViewer.ReportSource = crReport

    Dim fo As CrystalDecisions.CrystalReports.Engine.FieldObject = Nothing

    For i As Integer = 0 To crReport.ReportDefinition.ReportObjects.Count

    ReportType = crReport.ReportDefinition.ReportObjects(i).GetType.ToString

    If ReportType.Equals(ReportTypeCriteria) Then

    fo = DirectCast(crReport.ReportDefinition.ReportObjects(i), CrystalDecisions.CrystalReports.Engine.FieldObject)

    fo.ObjectFormat.EnableCanGrow = True

    End If

    Next

    Catch ex As Exception

    End Try

    End Sub

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

    ConfigureCrystalReports()

    End Sub

    Private Sub CodeBag()

    'public static void EnableReportFieldsMultiline(CrystalDecisions.CrystalReports.Engine.ReportDocument rep)

    '{

    ' CrystalDecisions.CrystalReports.Engine.FieldObject fo;

    ' for (int i = 0; i < rep.ReportDefinition.ReportObjects.Count; i++)

    ' {

    ' if (rep.ReportDefinition.ReportObjects[i] is CrystalDecisions.CrystalReports.Engine.FieldObject)

    ' {

    ' fo = (CrystalDecisions.CrystalReports.Engine.FieldObject)rep.ReportDefinition.ReportObjects[i];

    ' fo.ObjectFormat.EnableCanGrow = true;

    ' }

    ' }

    '}

     

    End Sub

    End Class

    Monday, June 16, 2008 12:21 PM
  • User-1330070619 posted

    I did something very similar to your code for programmatically changing the property. It changes the propery (cangrow) fine but as I said before, if the line is more than one, its vertical alignment also changes slightly and do not perfectly line-up.

    I created a new project for this bug only. It is using the MS SQL 2005 sample database AdventureWorks and just pulled-out some data to show the problem plus the screenshot and the pdf version of the report and sent it to your email address you give above.

    Monday, June 16, 2008 7:32 PM
  • User-1520240719 posted

    Were you able to resolve this issue? I' m having a similar problem.I have too many columns.I tried fit them in using Landscape mode but fields run over each other. Please advise.

     

    Thanks!!

    Thursday, July 3, 2008 10:30 AM
  • User-1330070619 posted

    Not neatly! I am currently using the CanGrow workaround as I mentioned above and hoping tsttntice will give me a clean solution.

    Thursday, July 3, 2008 10:54 AM
  • User2125237006 posted

    Sorry for the lengthy absence.  I got swollowed up in my project. 

    I was able to review the source code and duplicate the bug.  To me, I consider this a bug.  To Business Decisions (own Crystal Reports...for now) this may be a feature.  The default behavior of the data form field seems to be to grow to the right.  The can grow property seems to control vertical growth. 

    I was able to find one solution that doesn't take very much effort.  I stopped there rather than dive into a code solution but I suspect this can also be genereted by the code side.

    To start with, make sure the value in the report field is a text string.  If it is, then this format edit will truncate the text to be the same size as the box on your form.

    Right mouse click over the report field on your report and click 'Format Object'.  On the Paragraph Tab choose the 'Text Interpretation' value and change it to 'RTF Text'.  This will truncate text values.

    Now on the example, we used the the AdventureWorks SQL database.  The field we used was Production.Product.ProductNumber which is the type: nVarChar(25).  This did not truncate properly until I created a function on the Crystal Report that converted it to Text.  Then I inserted the function field rather than the Report Field on the report and set the format to RTF Text as noted above.  This allowed it to truncate to the length of the box.

    The function was easy.  Create a New Function in Crystal: I named mine ProductNumberTrim and set the formula to :  ToText({Product.ProductNumber})

    It wasn't that bad to correct but a bit of a nuesance.  If there are some coding ways to do the same thing someone can run with it and post it here but I don't think it would save any effort.

    This worked for me in Visual Studio 2005 Crystal Reports version and in Crystal Reports 11.5.  Good luck.

    Thursday, July 3, 2008 12:01 PM
  • User-1330070619 posted

    Thanks tsttntice,

    I tried your workaround but I believe it was just a coincidence that you thought the workaround worked well. It is now overwriting in a different way. However, it still half works:

    1. Setting TextInterpretation property to RTFText cuts the string. (This is the half-working part).

    2. However, if the string contains hyphens (-) that happen to be be close to the selected width of the field object, and may be also with a combination of space character, the string gets cut at the hyphen and the remaining part gets printed to the line below (even though you choose a single line!).

    3. Creating a ToText function field does not solve this problem, it behaves exacly the same. I think you thought it fixed the problem because you probably used the function field with different width and the hypen conveniently got placed without creating the problem. If you choose the exact same width as the original field, you will see the problem still remains. You can also test the same thing in Name field of the sample database as the product number has problems in the first few and the Name has problems towards the end. If you have not changed font sizes or any other values, you can set the widths of ProductNumber and Name to 687 and 954 to see how it shows.

    I think I am running out of luck...

    Thursday, July 3, 2008 10:57 PM
  • User2125237006 posted

    You are correct.  The hyphen does seem to throw a word wrap at the width you specified.  Oddly enough I found yet another format setting that can mitigate that.  If you mark the "Can Grow" checkbox on the function field and then set the maximum number of lines to 1, it displays properly for me.

     So many work arounds...this can get frustrating.  Crystal has always been quirky this way yet it is still one of the most commonly used reporting tools.

     Again, hope this works for you.

     Let me add that this worked on your Data Field also, not just the Function with the ToText method.  I think the ToText method was not necessary after all.

    Tuesday, July 8, 2008 4:18 PM
  • User-1330070619 posted

    I think your workaround suggestion is the same as the one I mentioned in the third post, which I am currently doing any way despite its slight vertical misalignment. I left the design as it is and changing these properties programmatically, just in case the next version has a fix I can remove the function calls! 

            public static void EnableReportFieldsMultiline(CrystalDecisions.CrystalReports.Engine.ReportDocument rep)
            {
                CrystalDecisions.CrystalReports.Engine.FieldObject fo;
                for (int i = 0; i < rep.ReportDefinition.ReportObjects.Count; i++)
                {
                    if (rep.ReportDefinition.ReportObjects[i] is CrystalDecisions.CrystalReports.Engine.FieldObject)
                    {
                        fo = (CrystalDecisions.CrystalReports.Engine.FieldObject)rep.ReportDefinition.ReportObjects[i];
                        fo.ObjectFormat.EnableCanGrow = true;
                    }
                }
            }
    
    Note that I did not include changing the MaxNumberOfLines since I still could not figure out how to change it (http://forums.asp.net/t/1260716.aspx). In the meantime, I leave with multiple lines.
    Tuesday, July 8, 2008 10:40 PM
  • User1068179023 posted

    Can Grow Max line =1 works fine with me

    Wednesday, July 9, 2008 9:46 AM
  • User2125237006 posted

    I tried to find a code way to set the maximum number of lines but cannot find it.  It does work if set in the Report Designer.

    I found this article on BusinessObjects.com. 

    http://tinyurl.com/58ccvu

    or

    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes/sdn_oss_boj_erq/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes{6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333233313336333633343335}.do

     Symptom

    A web application uses Crystal Reports for Visual Studio .NET as the reporting development tool. When previewing a report, a text object will always word wrap even if the Can Grow option is disabled. The text does not truncate.

    In the Crystal Reports designer, a text object will truncate if Can Grow is turned off.

     


    Cause

    The issue has been identified and tracked under ID ADAPT00227608.


    NOTE

    When a Track ID has been assigned to an issue, this indicates it has been reported to Business Objects for possible inclusion in future hot fixes or file updates. Refer to the list of Track IDs that accompanies a hot fix or file update to verify that a particular issue has been corrected.


     


    Resolution

    At the publication time of this article, an available workaround does not exist.

     

    Wednesday, July 9, 2008 12:39 PM
  • User-1330070619 posted

    I guess we just have to monitor the bug and download the fix when released. At least there is an acknowledgement! Thanks for getting down into that detail.

    Wednesday, July 9, 2008 6:41 PM
  • User1610800555 posted

     Hi friend i have more than 50 fields in my crystal report i cannot set width for TextObject(title) i can but show like this

    Student N -> original one is Student Name, i can't see N(ame)

    Siva

    Wednesday, March 11, 2009 2:22 AM
  • User1441518616 posted

    This can be resolved by selecting 'Can Grow' and setting the maximum number of lines to 1.

    Monday, October 10, 2011 12:30 PM