Crystal report fields spill-over - do not clip

Last post 07-03-2008 10:57 PM by jsdude99. 12 replies.

Sort Posts:

  • Crystal report fields spill-over - do not clip

    05-12-2008, 3:13 AM
    • Loading...
    • jsdude99
    • Joined on 04-21-2008, 6:39 PM
    • Sydney
    • Posts 88

    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.

  • Re: Crystal report fields spill-over - do not clip

    06-12-2008, 1:02 PM
    • Loading...
    • tsttntice
    • Joined on 06-12-2008, 4:53 PM
    • Lexington, KY
    • Posts 6

    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.

  • Re: Crystal report fields spill-over - do not clip

    06-12-2008, 7:13 PM
    • Loading...
    • jsdude99
    • Joined on 04-21-2008, 6:39 PM
    • Sydney
    • Posts 88

    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.

  • Re: Crystal report fields spill-over - do not clip

    06-12-2008, 8:29 PM
    • Loading...
    • tsttntice
    • Joined on 06-12-2008, 4:53 PM
    • Lexington, KY
    • Posts 6

    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.

  • Re: Crystal report fields spill-over - do not clip

    06-12-2008, 8:38 PM
    • Loading...
    • tsttntice
    • Joined on 06-12-2008, 4:53 PM
    • Lexington, KY
    • Posts 6

    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.

  • Re: Crystal report fields spill-over - do not clip

    06-15-2008, 8:31 PM
    • Loading...
    • jsdude99
    • Joined on 04-21-2008, 6:39 PM
    • Sydney
    • Posts 88

    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.

  • Re: Crystal report fields spill-over - do not clip

    06-16-2008, 8:58 AM
    • Loading...
    • tsttntice
    • Joined on 06-12-2008, 4:53 PM
    • Lexington, KY
    • Posts 6

    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.

  • Re: Crystal report fields spill-over - do not clip

    06-16-2008, 12:21 PM
    • Loading...
    • tsttntice
    • Joined on 06-12-2008, 4:53 PM
    • Lexington, KY
    • Posts 6

    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

  • Re: Crystal report fields spill-over - do not clip

    06-16-2008, 7:32 PM
    • Loading...
    • jsdude99
    • Joined on 04-21-2008, 6:39 PM
    • Sydney
    • Posts 88

    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.

  • Re: Crystal report fields spill-over - do not clip

    07-03-2008, 10:30 AM
    • Loading...
    • rkodur
    • Joined on 07-03-2008, 2:26 PM
    • Posts 1

    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!!

  • Re: Crystal report fields spill-over - do not clip

    07-03-2008, 10:54 AM
    • Loading...
    • jsdude99
    • Joined on 04-21-2008, 6:39 PM
    • Sydney
    • Posts 88

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

  • Re: Crystal report fields spill-over - do not clip

    07-03-2008, 12:01 PM
    • Loading...
    • tsttntice
    • Joined on 06-12-2008, 4:53 PM
    • Lexington, KY
    • Posts 6

    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.

  • Re: Crystal report fields spill-over - do not clip

    07-03-2008, 10:57 PM
    • Loading...
    • jsdude99
    • Joined on 04-21-2008, 6:39 PM
    • Sydney
    • Posts 88

    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...

Page 1 of 1 (13 items)