4 Answers, 1 is accepted
Out of the box the TextBox item can only grow vertically downwards pushing any other items below it.
However you can use some custom logic to calculate the textbox width based on value length and set it with Binding. Additionally our suggestion is to use a monospaced font.
Property path |
Expression |
Size |
=CalculateSize(ReportItem) |
public
static
Telerik.Reporting.Drawing.SizeU CalculateSize(Telerik.Reporting.Processing.TextBox textBox)
{
int
len = textBox.DataObject[
"Name"
].ToString().Length;
double
width = len * 6;
//this is pseudo calculation
return
new
Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Pixel(width), textBox.Size.Height);
}
All the best,
Peter
the Telerik team
HAPPY WITH REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!
Negin
Hello,
How do you make this code working :
public
static
Telerik.Reporting.Drawing.SizeU CalculateSize(Telerik.Reporting.Processing.TextBox textBox)
{
int
len = textBox.DataObject[
"Name"
].ToString().Length;
double
width = len * 6;
//this is pseudo calculation
return
new
Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Pixel(width), textBox.Size.Height);
}
I try to modify font size of a textbox dynamically depending of text length but when I use this user function, I have and error message :
System.NullReferenceException : 'Object reference not set to an instance of an object.'
Telerik.Reporting.Processing.IDataObject.this[string].get retournée null.
I have set the binding as describe above and when I debug I have my textbox which is passed to the function. I don't understand why I can't get the value of the textbox. For information, i'm passing an object to the report and the textbox is binded to a field of this object. I execute RenderReport ( To generate a PDF ).
Do you have an idea ?
Thank you
Hello Alexandre,
According the code the data source should provide field with name "Name". If such field is not available replace the named indexer in the code snippet with the available field in this line:
int len = textBox.DataObject["Name"].ToString().Length;
Regards,
Peter
Progress Telerik