INFO: Three Important ActiveReports Design Rules


08-26-2005, 3:16 PM

There are three golden rules when designing with ActiveReports. If any of the following rules are broken, you may see sections firing incorrectly, incorrect data, missing data rows, etc.

The following rules should never be broken:

  1. Never access the Fields collection outside of the FetchData or DataInitialize events.

    For example, the following code will cause problems in the Detail section Format event:

      
    C#
    this.TextBox1.Text = this.Fields["ProductName"].Value.ToString();
      
    VB.NET
    Me.TextBox1.Text = this.Fields["ProductName"].Value.ToString()

    Why this will cause problems:

    In ActiveReports there are a few event sequences that you can count on, such as a particular section's Format event firing before the BeforePrint event, and the BeforePrint event firing before the AfterPrint event. However, some sections will change the order in which events fire depending on the report layout, property settings, etc. The FetchData event may fire several times before the Detail Format event does. Every time the FetchData event fires, a row of data is processed. ActiveReports knows how to handle this and the report will generate correctly. However, if you are referencing the Fields collection from another section, such as the Detail Format event, it is not guaranteed to be pointing at the same record as the one being processed. In other words, you may be grabbing a value from the wrong record. There is never a need to access the Fields collection outside of the FetchData or DataInitialize event.

  2. Never access controls or sections (after the ReportStart event) from an event that is not one of the three events for the section which contains the control.

    For example, the following code will cause problems in the Detail section Format event:

      
    C#
    this.Sections["GroupHeader1"].Controls["lblIsValid"].Text = True;
      
    VB.NET
    Me.Sections["GroupHeader1"].Controls["lblIsValid"].Text = True

    Why this will cause problems:

    ActiveReports is not processing the GroupHeader section when the Detail Format event fires. In fact, it may have already been rendered. This can cause strange behavior in your report output and should never be done.

  3. Do not overlap controls that have the CanGrow property set to True.

    Why this will cause problems:

    ActiveReports needs space to insert page breaks. There should be clear horizontal spaces on the report where page breaks can be inserted. Otherwise, text will get split. If you are seeing text that is split across pages, the most probable cause is that you have overlapping controls on your report which are causing the issue.