This is a migrated thread and some comments may be shown as answers.

Create textboxes dynamically and set width

1 Answer 155 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 16 Jan 2009, 08:27 PM
I have data that is dynamic, so I am creating the report programmatically.   So I am creating textboxes through code.  Say one of my fields has text that is 10 characters in length.   How can I create a SizeU to assign to the size property so that it will fit all 10 of my characters (without going under or over)? 

What I'm trying to do is set the widths of all my textbox fields to be the maximum length of my data so my report looks nice.

1 Answer, 1 is accepted

Sort by
0
Jafin
Top achievements
Rank 2
answered on 19 Jan 2009, 02:15 AM
In the ItemDataBound event you could loop through the textbox controls and get the text contents length.  You could then create a formula for your particular font size to expand the box as required.

Ie if you use Arial 9pt and the size of each character is about .25cm then you could have logic like:

Report_ItemDataBound(sender, eventargs)
if (reportItembase is TextBox)
  ((TextBox)reportItemBase).Size = new SizeU(textBox.Text.Length * .25, UnitType.Cm), height)

If you are wanting this to work for autogenerated columns then you'll probably need to resize any header/footer tags as well to match the detail textboxes.

Tags
General Discussions
Asked by
Scott
Top achievements
Rank 1
Answers by
Jafin
Top achievements
Rank 2
Share this question
or