问题
I have tried a lot to maintain long text inside RDLC report's columns but it doesn't seem to be adjustable. When some long text appears inside any column then it disturbs the whole report. How to control it, so the text keeps extending downwards in proper and good manner.
回答1:
Try and put a fixed Column Width and set CanGrow
to False and make sure that the Row has it set on True.
If that doesn't work you'll have to edit your datasource before giving it to the reporter. You must break the value into multiple lines based on the length of the string. You can achieve this by inserting System.Environment.NewLine
every time it exceeds the size. The exact length at which you need to insert the line breaks depends on your maximum column width and you'll have to calculate this yourself by trial and error until you find the perfect fit.
Edit: Including step by step process for adding break lines based on text size.
Calculate the length of the string and add
Environment.NewLine
where needed to force the text to break to a new line.
- Use Graphics.MeasureString to calculate the size of your text in pixels.
- Check if the width exceeds the maximum length of your TextBox.
- If the string fits, add it to the final string and continue to step 4.
- If the string doesn't fit, continue to step 3.
- Remove a character of the string, insert that character to the front of a new (second) sting and repeat step 1. again until the first string fits.
- Check if the second string is empty.
- If the second string is empty, we're finished. (The final string can be added to the TextBox / new datasource).
- If the second string isn't empty, add an
Environment.NewLine
at the end of the final string and replace the first string with the second one and make the second string empty again, repeat the whole process.
There might be ways of improving this process. For example by breaking the text in fixed predefined intervals and refining it afterwards. Or if there are actual words divided by spaces you could add and remove words instead of characters.
回答2:
- Cut the long-length
textbox
. - Drag and drop a
rectangle
there. - Paste the
textbox
inside therectangle
. - Set rectangle's borders
as the textbox was.
Note: your textbox must be
Cangrow:true
来源:https://stackoverflow.com/questions/32594761/how-to-maintain-long-text-inside-rdlc-report-column