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

binding subreport through constructor

2 Answers 120 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 14 Aug 2015, 08:25 PM

Hello

I have a masterreport containing a subreport i need to bind to a quoteobject.



My masterreports datasource are set via an overloaded contructor like:

        public masterreport(string P1, string P2)
        {
            InitializeComponent();

            //set masterreport datasource  (Works fine)

            Quote q = new Quote(​P1, ​P2);
            this.DataSource = q;

            //load subreportcontrol   (doesent work!)

            this.subReport1.ReportSource = new BackEnd.Reports.mysubreport(q);

        }

 

  my subreports overloaded constructor looks like :

        public subreport(Quote ​q)
        {
            this.DataSource = ​q.cfgs;  //cfgs is List<quotelines>    
        }



The masterreport is loaded into a reportviewer using :

 this.ReportViewer1.ReportSource = new BackEnd.Reports.masterreport("param1","param2");



Result is ok regarding the masterreport, where as the subreport doesent load.
The subreport works fine if I bind a datasource in the designer.

Should the above not work for binding the subreport, or have i missed something?


any inputs are welcome

Regards  
MArk


2 Answers, 1 is accepted

Sort by
0
Accepted
Nasko
Telerik team
answered on 18 Aug 2015, 12:50 PM
Mark,

Modifying the default parameterless constructor of the report is not recommended. To bind the master report to data use the ObjectDataSource Component.

To pass the q.cfg object from the master report to the sub-report, use a Binding to the subreport's data source as described in the How to use the ReportItem.DataObject property in expressions  article.

Regards,
Nasko
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
0
Mark
Top achievements
Rank 1
answered on 18 Aug 2015, 03:03 PM

Thanks for your answer.

I have successfully connected the object to both Master/slave report as you suggest.

However I need to have my object "up close" in the construct​or, to be able to do various tweaks to the report.

I found a flaw in the above code, which resolved the matter. 

"InitializeComponent();" was missing in my subreport constructor.  (sigh!)

Regards

 Mark

Tags
General Discussions
Asked by
Mark
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Mark
Top achievements
Rank 1
Share this question
or