Page 1 of 1

StiGroupHeader.Rendering event called twice

Posted: Wed Mar 21, 2007 3:26 am
by robert
Hi,

When my report starts a new page it appears that Rendering event is being called twice. This cause a big problem for me as I'm using it preform calculations. It is difficult for me to give a full repo of this since my code builds up the report controls dyncamically, but I do something like:

Code: Select all

public override void Sum(Reports_Description_expression arg0) {
    StiSumDoubleFunctionService sum = new StiSumDoubleFunctionService();
    variables.Enqueue(sum);

    StiGroupHeaderBand groupHeaderBand = band as StiGroupHeaderBand;
    if (groupHeaderBand != null) {
        groupHeaderBand.BeginRender += delegate(object sender, System.EventArgs e) {
            sum.Init();
        };
        groupHeaderBand.Rendering += delegate(object sender, System.EventArgs e) {
            double result = Evaluate_expression.Execute(arg0, variables, text, connection, band);
            File.AppendAllText("out.txt", string.Format("{0} - {1}\r\n", connection["id"], result));
            sum.CalcItem(result);
        };
    }
}
I see in the out.txt that items appear on the first row of a new page in the report appear twice as many others. What could becausing this? Is there a fix/work round for this.

Thanks,
Rob

StiGroupHeader.Rendering event called twice

Posted: Wed Mar 21, 2007 8:37 am
by Vital
This behavior is correct. On each new page report engine rerenders previous row because data may be changes on new page. To fix problem you need to use variables declared in report dictionary or events:
SaveState and RestoreState of the report. How report engine use this events you can see in the report code. For example:

Code: Select all

public override void SaveState(System.String stateName)
        {
            base.SaveState(stateName);
            this.States.PushInt(stateName, this, "Variable", this.Variable);
        }
        
        public override void RestoreState(System.String stateName)
        {
            base.RestoreState(stateName);
            this.Variable = this.States.PopInt(stateName, this, "Variable");
        }
This code allows report engine to store report variable correctly.

Thank you.

StiGroupHeader.Rendering event called twice

Posted: Wed Mar 21, 2007 9:18 am
by robert
Unfortunatly this would be very difficult due to the design of my reports. Is it possible to detect this is the second time the event has been fired? This would be much easier for me.

Thanks,
Rob

StiGroupHeader.Rendering event called twice

Posted: Wed Mar 21, 2007 9:36 am
by Edward
You may check this via current Position of the DataSource which is assigned to the DataBand. So for the first time you have to save DataSource.Position in to the variable for example CurrentPosition and then when the event fires again, if condition

Code: Select all

DataSource.Position == CurrentPosition 
succeeds, then it means that the event fires again.

It works usually with 100% success.

Thank you.

StiGroupHeader.Rendering event called twice

Posted: Wed Mar 21, 2007 10:51 am
by robert
Thanks that solution worked a treat.

Cheers,
Rob