Ticket Q410350
Visible to All Users

XtraReports 11.2 entity framework - subreports don't work

created 13 years ago

Hello,

I use XtraReport Suite 11.2 and entity data model to connect to mysql server. I need to create report containing one subreport. There are 2 database views - one view for report and other view for subreport. Reports are bound to database fields at runtime, by handling DataSourceDemanded event for report, this way (and also at design time by adding bindingSource control):

C#
void rep_DataSourceDemanded(object sender, EventArgs e) { using (var ctx = new biatelbit_kancelaria_tajnaEntities()) { var fieldList = (from d in ctx.v_ra_osoby_uprawnione selectd).ToList(); BindingSource bs = new BindingSource() { DataSource = fieldList }; rep.DataSource = bs; } }

Similar code is reponsible for subreport database bind. As discussed here: http://www.devexpress.com/Support/Center/Question/Details/Q410007 about report parameters, it seems I need to use DataSourceDemanded to data refresh after parameters submit. Everthing works - parameters are passed correctly, report filtering works.

Next, I'm trying to create subreport, like described in this tutorial: http://documentation.devexpress.com/#XtraReports/CustomDocument4629 . So the steps are:
- add parameter and filter string to subreport with all neccessary settings

- place subreport control on main report and handle BeforePrint event to pass ID parameter and filter subreport view

- select subreport as report source on subreport control properties

To be sure that everything works, I've also test subreport parameter by setting it as visible and invoking print preview for subreport - everything works. But: it does not work if subreport is invoked by subreport control. In this case, all static controls are printed, but there are no data loaded from database - also, DataSurceDemanded never occurs in this case. And no database data loaded, never.

What's the problem and why subreport doesn't even ask for data if it is invoked from subreport control, but it asks for data it regular print preview?

Do you have any solution? How to use Entity Framework to create subreport and pass data to it, if report control set as subreport don't even asks for data?

Comments (2)
DevExpress Support Team 13 years ago

    Hi Michal,
    Thank you for your report. I have created a small sample project by following the approach you described. Please review it and check that the subreport datasource is initialized and filtered at runtime. Feel free to modify my sample code to illustrate the issue. I will be glad to help you.

    MO MO
    Michal Olszewski 13 years ago

      Hello,
      Thanks for your example. Now, I know what's the problem but I have no idea how to solve it, but I believe you can help me with this.
      In your example, you did everything the same like I did, but there is only one difference. I need to add DataSourceDemanded dynamically, (in this example, in main form constructor). If I do this, instead of adding DataSourceDemanded using visual studio designer, DataSourceDemanded for subreport never occurs.
      There is modified example in attachment. I modified it to show you what I mean. After I do this, subreport stopped to work (but main rerpots works without any problems).
      What's wrong? What should I do to make it possible to assign this events dynamically?

      Answers

      created 13 years ago (modified 13 years ago)

      Michal,
      To resolve the issue, assign a newly created XtraReport (subreport) instance to the XRSubreport.ReportSource property:

      C#
      public Form1() { InitializeComponent(); report = new XtraReport1(); subreport = new XtraReport2(); XRSubreport subr = (XRSubreport)report.FindControl("xrSubreport1", true); subr.ReportSource = subreport; report.DataSourceDemanded += new EventHandler<EventArgs>(report_DataSourceDemanded); subreport.DataSourceDemanded += new EventHandler<EventArgs>(subreport_DataSourceDemanded); }
        Comments (2)
        MO MO
        Michal Olszewski 13 years ago

          Hello,
          It works, you can mark this thread as solved. Thanks.

          DevExpress Support Team 13 years ago

            Hi Michal,
            Thank you for your response. Please feel free to contact us if you have any further difficulties. We will do our best to help you.

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.