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

using a member variable of the Report object

5 Answers 671 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 12 Jun 2014, 07:58 PM

Hi, it seems like this should be simple, but I must have a scope or a namespace wrong.  Any help would be appreciated.  Using Telerik.Reporting in C#.NET, Winforms.

I am trying to generate a report for an invoice.  Using the Invoice object as a datasource wasn't working for me, so I instead am using the LineItems as the datasource.   However, there is a lot of header data that I don't want to have to use ReportParameters for - I have the Header as an object, so I'd like to reference the Header directly from the designer.

So I have this as my class code: 
    public partial class InvoiceBalancingReport : Telerik.Reporting.Report
    {
        public InvoiceHeader Header { get; set; }

        public InvoiceBalancingReport(Invoice inv)
        {
            //
            // Required for telerik Reporting designer support
            //
            InitializeComponent();

            Header = inv.Header;
            DataSource = inv.LineItems;       
        }

In a TextBox in the PageHeader section of the report, I then have [ = Header.InvoiceID ] as the text value.

But when I run the report, it cannot find the Header object.  So how do I access that public member variable of the report object?

5 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 16 Jun 2014, 03:07 PM

 I can't imagine that this would be very hard to do.  I mean, the DataSource is a member property, so obviously the parser has to have access to members at runtime (for that matter, the TextBoxes themselves are member controls of the Report object).

It wouldn't be so difficult if I could pass Header as a ReportParameter, but ReportParameter is hardwired to only use a few (mostly-primitive) types.  It seems oddly restrictive that ReportParameter has a "Type" property that doesn't take a System.Type object, but instead is an Enum with just a few allowable types.
0
Nasko
Telerik team
answered on 17 Jun 2014, 12:36 PM
Hello Chris,

The issue with the described approach is that the Report class actually does not have a Header property. You can check the Report class members in the Reporting API Reference.

Additionally, the Page Header section cannot be bound to a separate data source. The report has only one data source specified in the Report.DataSource property. For more information, please refer to the Report Structure help article. Note that it is recommended to use one of our data source components to set the report's data source. Further details can be found in the Connecting to Data help article.

You can use the data from a separate data source in conjunction with a data item inside the report. The data items display and manipulate data in Telerik Reports. With a data item, you can group, sort, filter, and aggregate data from a single data source. Telerik Reporting provides several types of data items: Report (SubReport), Table, Crosstab, List, Graph and Map.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Chris
Top achievements
Rank 1
answered on 17 Jun 2014, 03:15 PM
The "Report" class doesn't have a Header property, but my InvoiceBalancingReport *does*.  It is a subclass of Report - that's kind of the whole point of subclassing - to add functionality.  I just need to figure out how to reference a member property from within the designer for that subclass.

The DataSource isn't my problem.  I can set the DataSource to be the LineItems from the invoice.  Using fields from that DataSource for the PageHeader section has the issue that it basically requires everything to be aggregates from the Fields object -  I have all sorts of functionality already built into the InvoiceHeader object that could be leveraged in the designer.  Moving all of the Header data to ReportParameters (which I assume is how you expect users to handle this situation?), is a workaround, but is suboptimal, partially because the ReportParameters class is so limited.  For example, "ToString" overrides on objects that would make them easy to display if I could access them, but ReportParameters is hardwired to only take a few different data types.  It also takes each step that could be done with "[ = Header.SomeParameter]" to a 3 step process that includes adding a new ReportParameter, and setting that ReportParameter in the report constructor.
0
Nasko
Telerik team
answered on 20 Jun 2014, 10:35 AM
Hello Chris,

You can use the following expression to access your public report definition property Header:

= ReportItem.Report.ItemDefinition.Header

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Chris
Top achievements
Rank 1
answered on 20 Jun 2014, 06:30 PM
[quote]You can use the following expression to access your public report definition property Header:

= ReportItem.Report.ItemDefinition.Header
[/quote]

Thanks.  Haven't tested it yet, but that sounds like the exact thing I need.
Tags
General Discussions
Asked by
Chris
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Nasko
Telerik team
Share this question
or