Question

I am having some trouble with getting the formatting to occur correctly. I believe it stems from what is probably incorrect understanding of the events that I am attempting to make the changes in.

any direction would be great

    private void so_FetchData(object sender, FetchEventArgs eArgs)
    {
        if (m_so != null && m_so.Rows.Count > (m_soRowCount + 1))
        {
            DataRow soDr = m_so.Rows[m_soRowCount++];
            if (soDr != null)
            {
                var compResID = (int) soDr["CompResID"];
                var result = (ComplianceLevel) soDr["Result"];
                var sectNum = (int) soDr["JobSectType"];
                var sectName = soDr["S" + sectNum + "Name"] as string;
                var sectTxt = soDr["S" + sectNum + "Text"] as string;

                Fields["CompLev"].Value = (result == ComplianceLevel.OtherThanSerious) ? "Other Than Serious" : result.ToString();

                m_sectInfo = new SectInfo(sectName, sectTxt);
                m_causes = new Causes(compResID);
                m_actions = new Actions(compResID);
                subReport1.Report = m_sectInfo;
                subReport2.Report = m_causes;
                subReport3.Report = m_actions;
                eArgs.EOF = false;
            }
        }
        else
        {
            eArgs.EOF = true;
        }
    }

    private void eh_BeforePrint(object sender, EventArgs e)
    {
        //decide where the bottom border should be draw to
        if (m_actions != null && m_actions.ShouldShowBottBorder)
        {
            subReport3.Border.BottomStyle = BorderLineStyle.ThickSolid;
            subReport2.Border.BottomStyle = BorderLineStyle.Solid;
        }
        else if (m_causes != null && m_causes.ShouldShowBottBorder)
        {
            subReport2.Border.BottomStyle = BorderLineStyle.ThickSolid;
        }
        else
        {
            subReport1.Border.BottomStyle = BorderLineStyle.ThickSolid;
        }
    }

the issue is that every time I step through the eh_BeforePrint method, the values always equate to false even though I step through the sub reports and the values are properly set. What is happening to cause the bool property to reset to false?

Just changing it if there are any records to print in the Fetch_Data method of each sub report.

    private void Causes_FetchData(object sender, FetchEventArgs eArgs)
    {
        if (m_pos < m_corrs.Count)
        {
            if (!ShouldShowBottBorder)
                ShouldShowBottBorder = true;
            //...
         } 
     }
Was it helpful?

Solution

You cannot be assured that the BeforePrint event raises exactly after the corresponding FetchData event. For example, FetchData may fire many times for several records, but due to some keep together logic in the layout engine, it may take several records before ActiveReports knows which page it will commit a section to. Therefore, it is pretty common for FetchData to be raised for several events before the corresponding BeforePrint events are raised.

If I understand your code properly there is a bigger problem though. It appears you are calculating values in your subreports (m_causes and m_actions appear to be actual subreports). If that is the case you cannot reliably calculate values in your subreports and pass them out to the parent report. Instead, you'll need to calculate those values in your parent report. However, usually you can add some shared function to calculate the value and call it from the parent report, and then pass that value into the subreports.

Comment here with some more information if you have specific questions about doing that.

On an unrelated note, you can get a pretty significant performance boost if you change the way you're initializing your subreports. Always initialize your subreports in the ReportStart event and then set their data in the format event of the section containing the Subreport control. This way you initialize each subreport once instead of initializing each subureport for every record. For example:

private void so_ReportStart()
{
    subreport1.Report = new SectInfo();
    subreport2.Report = new Causes();
    subreport3.Report = new Actions();
}
private void Detail_Format()
{ // assuming Detail is the section containing your subreports:

    ((SectInfo)subreport1.Report).SetParameters(Fields["sectName"].Value, Fields["sectTxt"].Value);
    ((Causes)subreport2.Report).SetParameters(Fields["compResID"].Value);
    ((Actions)subreport3.Report).SetParameters(Fields["compResID"].Value);
}

You would setup those "Fields" values in FetchData similar to how your initializing the subreports now. Something like the following:

private void so_FetchData(object sender, FetchEventArgs eArgs)
{
    if (m_so != null && m_so.Rows.Count > (m_soRowCount + 1))
    {
        DataRow soDr = m_so.Rows[m_soRowCount++];
        if (soDr != null)
        {
            var compResID = (int) soDr["CompResID"];
            var result = (ComplianceLevel) soDr["Result"];
            var sectNum = (int) soDr["JobSectType"];
            var sectName = soDr["S" + sectNum + "Name"] as string;
            var sectTxt = soDr["S" + sectNum + "Text"] as string;

            Fields["CompLev"].Value = (result == ComplianceLevel.OtherThanSerious) ? "Other Than Serious" : result.ToString();
            /** BEGIN NEW CODE **/
            Fields["sectName"].Value = sectName;
            Fields["sectTxt"].Value = sectTxt;
            Fields["compResID"].Value = compResId;
            /** END NEW CODE **/

            /** OLD CODE:
            m_sectInfo = new SectInfo(sectName, sectTxt);
            m_causes = new Causes(compResID);
            m_actions = new Actions(compResID);
            subReport1.Report = m_sectInfo;
            subReport2.Report = m_causes;
            subReport3.Report = m_actions;
            **/     
            eArgs.EOF = false;
        }
    }
    else
    {
        eArgs.EOF = true;
    }
}

To learn more about the events in ActiveReports see the Report Events concepts topic in the ActiveReports Online Help. To learn more about passing data into Subreports see Subreports with Run-Time Data Sources in the ActiveReports Online Help.

Scott Willeke
GrapeCity inc.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top