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

Programmatically change CrossTable column widths depending on bound data

1 Answer 144 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tobias
Top achievements
Rank 1
Tobias asked on 04 Dec 2015, 08:07 PM

Hello,

I want to change the width of columns of a CrossTable depending of the bound data. I know how to change the columns but I do not know at what time I can do that. My report gets its data via object data source set from outside of the report as my following code shows:

01.var reportModel = new MainReportModel()
02.{
03.    Orders = _GetOrders()
04.};
05. 
06.ObjectDataSource objectDataSource = new ObjectDataSource();
07.objectDataSource.DataSource = reportModel;
08. 
09.var report = new Report1();
10.report.DataSource = objectDataSource;
11.  
12.InstanceReportSource instanceReportSource = new InstanceReportSource();
13.instanceReportSource.ReportDocument = report;
14.  
15.ReportProcessor reportProcessor = new ReportProcessor();
16.RenderingResult renderingResult = reportProcessor.RenderReport("PDF", instanceReportSource, null);
17.  
18.File.WriteAllBytes("test.pdf", renderingResult.DocumentBytes);

 

For design time I added an ObjectDataSource of type Order to the CrossTable. So I can use the expression designer for example. For render time I added a binding to my CrossTable to bind DataSource to the Orders property of MainReportModel.

Where can I hook into the process to get the bound data and change the CrossTable columns?

Greetings from Germany,

Tobias

1 Answer, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 08 Dec 2015, 04:37 PM
Hi Tobias,

If the data schema is different, the Table item's template will have to be modified before processing the report.

For the purpose you will need to get the new data schema and modify the Table item e.g.:
//get a report instance
var report = new MyReport();
report.Datasource = new MyDataModel();
 
//get the Table item
var table=report.Items.Find("table1",true)[0] as Telerik.Reporting.Table;
 
//modify the template by updating fields names or entirely reworking the item
ModifyTableItem(table);
//set the data source to a collection property of the data assigned to the report's DataSource
 table.Bindings.Add(new Telerik.Reporting.Binding("DataSource", "=Fields.MyCollectionProperty"));

//wrap the modified report in a report source object
var IRS = new InstanceReportSource { ReportDocument = report };


In the above example you can set the report's DataSource to a custom business object without wrapping it in a data source component. The Table item can be bound to a collection property of the report's data object e.g. the example elaborated in How to Databind to Collection Properties.

To modify the Table item you can create sample reports with the VS Report Designer and re-use the auto-generated code from the report's designer.cs file.


I hope this information is helpful.

Regards,
Stef
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
Tobias
Top achievements
Rank 1
Answers by
Stef
Telerik team
Share this question
or