3

I have an unbound XtraReport that has a subreport control which contains another report. I call "unbound" to a report that has the definition of the fields using a schema but not actually bound to any DataSet, I create a DataTable using a Data Access Layer and then pass that object to the DataSource property of the report.

So, I have the following code:

        // (...) Get the data from the db and fill a DataTable

        if (table.Rows.Count > 0)
        {
            report.DataSource = table;

            // (...) Get the data from the db and fill a DataTable for the subreport
            report.SubPurchaseOrder.Report.DataSource = tableSubReport;

            report.ShowPreviewDialog();
        }
        else
        {
            MessageBox.Show("No data to show.");
        }

But what I get using this approach is the subreport printed very oddly (take a look at the attached pdf, sorry it's in spanish but I think you get the idea).

I've read the DevExpress documentation and maybe I'm not getting the approach right, so my question to you is how to create a report that has one or more subreports but I have to provide the data to fill them using some process external to the reports, such as a Data Access Layer?

Please let me know if the question is not stated correctly or lacks of more info.

EDIT:

I uploaded a sample project with the report with problem here.

I've tried to use parameters of some kind. In the BeforePrint event of the subreport control, I tried:

((XRSubreport)sender).ReportSource.FilterString = "[IdPO_RO] = " + _idPurchaseOrder;

and

((XRSubreport)sender).ReportSource.Parameters["Id"].Value = _idPurchaseOrder;

Of course, for the second, I added a parameter and the filter string the same as the first but using the parameter.

Sebastian
  • 1,491
  • 6
  • 20
  • 29
  • Is the problem that the sub-report is repeating 16 times or that the data isn't getting bound to the labels? – Jacob Sep 29 '09 at 01:37
  • Yes, the data isn't showing in the labels. But as you can see with the labels that doesn't has a data source, the subreport is bound. – Sebastian Sep 29 '09 at 02:03
  • Another thing: when I call the subreport without having inside the main report, it does show all the data in the labels. – Sebastian Sep 29 '09 at 02:40

1 Answers1

3

I could solve the problem.

The cause for this was that I was assigning to the wrong object. This line:

report.SubPurchaseOrder.Report.DataSource = tableSubReport;

should be:

report.SubPurchaseOrder.ReportSource.DataSource = tableSubReport;

So the brief explanation is that I was using another property to refer to the report contained in the subreport control (XRSubreport).

Sebastian
  • 1,491
  • 6
  • 20
  • 29