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

Set The Size of TextBox Dynamically in Telerik Report

4 Answers 1464 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Negin
Top achievements
Rank 1
Negin asked on 28 Jan 2013, 09:47 AM
Hi,

Is there any way to set the size of a textbox dynamically based on length of its text in Telerik Reports?

Thanks.

4 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 30 Jan 2013, 10:12 AM
Hello Negin,

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!

0
Negin
Top achievements
Rank 1
answered on 31 Jan 2013, 04:31 PM
Thanks a lot,

Negin
0
Alexandre
Top achievements
Rank 1
answered on 10 Oct 2019, 10:03 AM

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

0
Peter
Telerik team
answered on 14 Oct 2019, 08:30 AM

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

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Negin
Top achievements
Rank 1
Answers by
Peter
Telerik team
Negin
Top achievements
Rank 1
Alexandre
Top achievements
Rank 1
Share this question
or