none
Disable text wrap word wrap RRS feed

  • Question

  • Crystal reports truncates text when it does not fit into a textbox.  It appears that the Microsoft Report Viewer wraps words to a new line which means that you can lose the last word if it does not quite fit into the textbox.  It will wrap to a new line and since I have CanGrow set to false, the word that is wrapped is not visible.

    Is there a way to turn off text wrapping or word wrapping?

    This is in Microsoft Report Viewer 2010 displayed as a LocalReport.

    Tuesday, September 14, 2010 12:53 PM

Answers

  • Hi Chris,

     

    Honestly, it is hard to create a generic function can adapt to different font.  Because the auto-warp is by design, if you feel it is not appropriate for your requirement, you can submit your suggestion at https://connect.microsoft.com/SQLServer

     

    Your feedback is valuable for us to improve our products and increase the level of service provided.

     

    If you have any question, please feel free to ask.

     

    Thanks,

    Tony Chain

    Wednesday, September 22, 2010 6:02 AM
    Moderator

All replies

  • Hi Chris,

     

    By default, if text does not fit into a textbox, the textbox will display text as the first picture shows. However, when set the CanGrow property to False, the textbox will only display the first line of text. So, do you mean you need to change this behavior to display the last part of text as the third picture shows?

     

    If so, one workaround is using the Right() function in expression to get only last several characters and display them in the textbox. If it is not what you need, please point out and post a sample so I can provide you further assistance.

     

    For more information Report Expressions, please see: http://msdn.microsoft.com/en-us/library/ms159238(v=SQL.100).aspx

     

    Thanks,

    Tony Chain

     

    Wednesday, September 15, 2010 9:33 AM
    Moderator
  • My problem is that I have a memo field that contains an address.  The address displays as below.

    JOHN DOE
    123 ANYSTREET
    THIS ADDRESS LINE IS TOO LONG TO FIT INTO THE
    TEXTBOX
    ANYTOWN, SS 12345

    Instead, I need the following.

    JOHN DOE
    123 ANYSTREET
    THIS ADDRESS LINE IS TOO LONG TO FIT INTO THE TEX
    ANYTOWN, SS 12345

    I need the word TEXTBOX to be truncated rather than wrap to the next line.

    Is there any way to do this in the Microsoft Report Viewer?

    Monday, September 20, 2010 3:24 PM
  • Hi Chris,

     

    Thank you for your explanation. As the example you posted, do you stored the address with newline format in the database and display the address with the format exactly in a multi-line textbox? When a line in the multi-line textbox is too long, you need to truncate is rather than add an extra newline, correct? If I have misunderstood, please point out.

     

    To truncate lines in a multi-line textbox, one workaround is control the character number of each line in TextBox by using custom code. Please post the data example stored in the memo filed and I will help you to achieve the custom code.  

     

    For more information about custom code references in Reporting Services, please see: http://msdn.microsoft.com/en-us/library/ms155798(v=SQL.100).aspx 

     

     

    We appreciate for your understanding. If you have any question, please feel free to ask.

     

    Regards,

    Tony Chain

    Tuesday, September 21, 2010 9:58 AM
    Moderator
  • I might be interested if a generic function could be written.  For example, if I could have a function like this...

    Public Function TruncateLine(ByVal StringToDisplay As String, ByVal TextBoxToDisplayIn As TextBox) As String

    The function would figure out the width of the TextBox, the FontFamily, FontSize, FontStyle, FontWeight, and TextAlignment.  Based upon this information, the function would return only the characters that could fit in the TextBox truncating from the left, right, or sides depending on the TextAlignment property.  Unfortunately, it looks like you are limited to a generic ReportItem object and have no access to the particulars of the TextBox.

    I do not want to hard code a bunch of TextBox widths and then have the report break any time the font, size, or alignment of any of the TextBoxes change.  I also do not want to truncate based on an arbitrary number of characters since we are talking about variable width fonts here.

    Tuesday, September 21, 2010 1:43 PM
  • Hi Chris,

     

    Honestly, it is hard to create a generic function can adapt to different font.  Because the auto-warp is by design, if you feel it is not appropriate for your requirement, you can submit your suggestion at https://connect.microsoft.com/SQLServer

     

    Your feedback is valuable for us to improve our products and increase the level of service provided.

     

    If you have any question, please feel free to ask.

     

    Thanks,

    Tony Chain

    Wednesday, September 22, 2010 6:02 AM
    Moderator
  • Thank you for the information Tony.
    Wednesday, September 22, 2010 12:38 PM
  • Hi all,

    I know this thread is little old, but still I need your help.

    My problem:

    I am using tablix control in rdlc. In one of its cell I have one expression which have large text. Now what happens that the text wraps to new line but it cuts the words in between. Actually it should wrap with complete words as shown below:

    Current:

    This is Sample Te xt to show in the  
    field.

    I need:

    This is sample
    Text to show in
    the field.

    Please help to achieve it.

    Thanks in advance.


    • Edited by Gadge Shyam Friday, August 23, 2013 10:09 AM
    Friday, August 23, 2013 10:08 AM
  • Crystal reports truncates text when it does not fit into a textbox.  It appears that the Microsoft Report Viewer wraps words to a new line which means that you can lose the last word if it does not quite fit into the textbox.  It will wrap to a new line and since I have CanGrow set to false, the word that is wrapped is not visible.

    Is there a way to turn off text wrapping or word wrapping?

    This is in Microsoft Report Viewer 2010 displayed as a LocalReport.


    Very late to the party, but if you require a single line of text to truncate anywhere - rather than rap to a new line at the spaces - you can insert a Unicode Zero Width Space character between every single character in the string.

    I fond the 'MONGOLIAN VOWEL SEPARATOR' (U+180E) worked best for me ('ZERO WIDTH SPACE' (U+200B) also worked on screen, but failed to show any spaces when I exported the RDLC to a PDF):

    'Convert a string into string separated by zero width spaces.  This means a string
    'that is too long for a field can be split anywhere, not just at a real space.
    Function ZWS(s As String) As String
        Dim sResult as String = ""
        Dim i as Integer
        For i = 0 to s.Length - 1
            If i > 0 Then
                sResult = sResult & ChrW(&h180E)
            End If
            sResult = sResult & s(i)
        Next i
        ZWS = sResult
    End Function
    

    Then in your place holder for your field, simply write the expression:
    =Code.ZWS(Fields!MyField.Value)

    Field truncating now works much more like Crystal, at least for single line fields.

    • Proposed as answer by Zip-News.com Tuesday, June 7, 2016 5:11 PM
    Wednesday, July 30, 2014 3:47 PM
  • There is a simple (though late) solution for the problem:
    If a wordwrap still occurs, although you have set the CanGrow property of a textbox to False, the reason may be, that the rendering machine still assumes, that there is enough vertical space to print a second line.
    In order to solve the issue, just decrease the Height of the textbox or increase their Padding Top- and/or Bottom values.
    • Proposed as answer by Dennis__V Wednesday, February 17, 2016 12:26 PM
    • Unproposed as answer by Dennis__V Wednesday, February 17, 2016 12:26 PM
    • Proposed as answer by M. A. Naveed Thursday, January 23, 2020 5:35 PM
    Thursday, January 14, 2016 11:01 AM
  • Trying to answer this but could not, so I just make this and it works if you build you text one line at a time.

    string s = drv["LocationNumber"].ToString() + " - " + drv["LocationName"].ToString();
    Size textSize = TextRenderer.MeasureText(s, GridHintTextBox.Font);
    while (textSize.Width > GridHintTextBox.Width)
    {
            s = s.Substring(0, s.Length - 1);
            textSize = TextRenderer.MeasureText(s, GridHintTextBox.Font);
    }
    GridHintTextBox.Text = s + "\r\n" + // other lines follow here

    Wednesday, February 17, 2016 12:31 PM
  • This works as perfectly as described above. Using Visual Studio 2015:

    1) From Toolbox add ReportViewer to Form. 2) From ReportViewer select Tasks Design a New Report. 3) While in design mode of NewReport.rdlc: Use Visual Studio's menu item "Report", then "Report Properties". 4) From Report Properties select Code, and paste the Function ZWS(s As String) As String ..full example.. End Function example above into the Custom Code for Report area.

    Using "=Code.ZWS(Fields!MyField.Value)" expression for your place holder of TextBox produces these:

    LastName, FirstNa

    THIS ADDRESS LIN

    Instead of these:

    LastName,

    FirstName

    THIS ADDRESS LINE

    IS TOO LONG TO FIT

    INTO THE TEXTBOX

    Thank you so much!




    • Edited by Zip-News.com Tuesday, June 7, 2016 5:15 PM Better Example of Results
    Tuesday, June 7, 2016 5:10 PM
  • NP - Glad it was of use to someone else.

    Also your reply adds extra detail of how to add the code snippet to the RDLC in the designer.  So that's useful. Not quite sure how I forgot to mention that originally...

    Wednesday, June 8, 2016 2:11 PM
  • Old thread but still useful, this padding solution worked like a charm!

    Cheers!

    Thursday, January 23, 2020 5:34 PM