SubReport print the next match record. How to make it print the right match record?

36 Views Asked by At

I have a report with a Subreport. Everything works fine when I put the subreport in a group header or Detail, but when I put it into a group footer (where we need it to go) the subreport shows the data from the next record. How can I fix this so it is grabbing the right data?

1

There are 1 best solutions below

0
QuangGiap On

I'm working with Active Reports 17. I created a BaseReport that inherits from the SectionReport to collectively handle the generation and printing of parent and subreports. This is how I create Parent and SubReport in ViewerForm:

private void btnCreateReport_Click(object sender, EventArgs e)
    {
        var _repCustomer = new BaseReport(dgvCustomer);

        var _rptInvoice = new BaseReport(dgvInvoice);

        var _rptAccount = new BaseReport(dgvAccount);

        List<BaseReport> subReports = new List<BaseReport>();
        subReports.Add(_rptInvoice);
        subReports.Add(_rptAccount);
        
        List<string> filterFields = new List<string>();
        filterFields.Add("CustomerID");
        filterFields.Add("CustomerID");

        _repCustomer.addSubReports(subReports, filterFields,"GroupFooter");

        arvMain.LoadDocument(_repCustomer);
    }

The addSubReport look like this:

public void addSubReports(List<BaseReport> pSubReports, List<string> pFilterFields, string pzSectionName)
    {
        Trace.WriteLine("Add SubReport");

        Sections.InsertGroupHF("GroupHeader", "GroupFooter");

        srm.GroupHeader _groupHeader = Sections["GroupHeader"] as srm.GroupHeader;

        srm.GroupFooter _groupFooter = Sections["GroupFooter"] as srm.GroupFooter;

        for (int _i = 0; _i < pSubReports.Count; _i++)
        {
            pSubReports[_i].Name = string.Format("SubReport{0}", _i);
            _groupHeader.DataField = pFilterFields[_i];

            srm.SubReport _subReportControl = new srm.SubReport();
            _subReportControl.Name = string.Format("SubReportControl{0}", _i);
            _subReportControl.Bounds = new RectangleF(0, 0.198F * _i, 11.0F, 0.198F);
            _subReportControl.Report = pSubReports[_i];

            Sections[pzSectionName].Controls.Add(_subReportControl);
        }

        for (int _j = _flexGrid.Cols.Fixed; _j < _flexGrid.Cols.Count; _j++)
        {
            srm.Label _columnHeader = new srm.Label();
            _columnHeader.Name = string.Format("lbl{0}", _flexGrid.Cols[_j].Name);
            _columnHeader.Text = _flexGrid.Cols[_j].Caption;

            _groupHeader.Controls.Add(_columnHeader);
        }

        _groupFooter.Format += _groupFooter_Format;
        _groupHeader.Format += _groupHeader_Format;
    }