Automatic column widths to fit contents

Stimulsoft Reports.WEB discussion
Post Reply
kkim
Posts: 3
Joined: Wed Jun 11, 2025 8:46 pm

Automatic column widths to fit contents

Post by kkim »

Hi,

I am trying to build a report that behaves like an HTML table in that all columns are lined up vertically with column headers and are sized to fit the longest text in a column (please see attached template). I have tried setting all text cells in the data band with AutoWidth=true, CanGrow=true and WordWrap=false. It does not work for me because longer texts simply overlap next cells on the right (see screenshot below). If I set DockStyle=left, things get even worse as cells are now totally misaligned vertically. Is there any way to achieve what I am looking for?

Thank you!
AutoColumnWidth.mrt
(18.19 KiB) Downloaded 22 times
sshot-78.png
sshot-78.png (28.02 KiB) Viewed 2538 times
Lech Kulikowski
Posts: 7358
Joined: Tue Mar 20, 2018 5:34 am

Re: Automatic column widths to fit contents

Post by Lech Kulikowski »

Hello,

There is no standard solution for this task.
As an option, you can use events and two passes: in the first pass, store the maximum column width into a variable, and in the second pass, set the component's width to this value.

Thank you.
nancyfett
Posts: 1
Joined: Tue Aug 26, 2025 10:30 am

Re: Automatic column widths to fit contents

Post by nancyfett »

kkim wrote: Mon Jul 28, 2025 10:55 pm Hi,

I am trying to build a report that behaves like an HTML table in that all columns are lined up vertically with column headers and are sized to fit the longest text in a column (please see attached template). I have tried setting all text cells in the data band with AutoWidth=true, CanGrow=true and WordWrap=false. It does not work for me because longer texts simply overlap next cells on the right (see screenshot below). If I set DockStyle=left, things get even worse as cells are now totally misaligned vertically. Is there any way to achieve what I am looking for?

Thank you!

AutoColumnWidth.mrt

sshot-78.png
You might want to use the Table component instead of placing text boxes individually. Tables handle auto-width and alignment much better.
Lech Kulikowski
Posts: 7358
Joined: Tue Mar 20, 2018 5:34 am

Re: Automatic column widths to fit contents

Post by Lech Kulikowski »

Hello,

Thank you for your suggestion.
Post Reply