How to get sum per page when using dynamic table?
Hello! I've built my table using its ManualBuild event. I have some int values in each row and the point is I want to calculate their's sum for each page and display it at the bottom of page.
For instance
N Name Age
- - - - - - - - -
1 Mike 30 <- Page 1, the sum is 59
2 John 29
- - - - - - - - -
3 Kyle 35 <- Page 2, the sum is 35
My ManualBuild looks like this
The problem is I don't know how to catch the moment when page ends. I tried to go through ResultTable calculating and sum'ing row's heights and to make PageBreak when I'm out of FreeSpace, but each row had the same Height and CalcHeight even if visually rows were different. So this attemp failed. Also I tried using events of different bands such as PageFooter, DataBand and so on but with no success.
Do somebody have an idea how could I get sum per page in my case?
For instance
N Name Age
- - - - - - - - -
1 Mike 30 <- Page 1, the sum is 59
2 John 29
- - - - - - - - -
3 Kyle 35 <- Page 2, the sum is 35
My ManualBuild looks like this
private void tabContent_ManualBuild(object sender, EventArgs e)
{
  tabContent.PrintRow(0);
  cTabContentHead.Text = "№";
  tabContent.Columns[0].Width = 47.25f;
  tabContent.PrintColumn(0);
  foreach (KeyValuePair<string, Dictionary<string, string>> item in tabColsSetup)
  {
    if (tabColsSetup[item.Key]["Leng"] != "0")
    {
      cTabContentHead.Text = tabColsSetup[item.Key]["Head"];
      tabContent.Columns[0].Width = float.Parse(tabColsSetup[item.Key]["Leng"], System.Globalization.CultureInfo.CurrentCulture.NumberFormat);
      tabContent.Columns[0].Width += fWidthRaise;
      tabContent.Columns[0].Width *= Units.Centimeters;
      tabContent.PrintColumn(0);
    }
  } Â
 Â
  while (tabdata.HasMoreRows)
  {
    tabContent.PrintRow(1);
    cTabContentContent.Text = rowN.ToString();
    tabContent.Columns[0].Width = 47.25f;
    tabContent.PrintColumn(0);
    foreach (KeyValuePair<string, Dictionary<string, string>> item in tabColsSetup)
    { Â
      if (tabColsSetup[item.Key]["Leng"] != "0")
      {                         Â
        cTabContentContent.Text = tabdata[item.Key].ToString();                                                         Â
        tabContent.PrintColumn(0);
      }
     Â
      switch (item.Key)
      {
        case "SharesAmount":
          Double.TryParse(ToFloatCulture(tabdata[item.Key].ToString()), out dSharesAmount);
          break;           Â
        case "SumFull":
          Double.TryParse(ToFloatCulture(tabdata[item.Key].ToString()), out dSumFull);
          break;
        case "Tax":
          Double.TryParse(ToFloatCulture(tabdata[item.Key].ToString()), out dTax);
          break;
        case "SumMinusTax":
          Double.TryParse(ToFloatCulture(tabdata[item.Key].ToString()), out dSumMinusTax);
          break;
      }
   Â
    }
   Â
    dPageTotalSharesAmount += dSharesAmount;
    dPageTotalSumFull += dSumFull;
    dPageTotalTax += dTax;
    dPageTotalSumMinusTax += dSumMinusTax;
   Â
    dTotalSharesAmount += dSharesAmount;
    dTotalSumFull += dSumFull;
    dTotalTax += dTax;
    dTotalSumMinusTax += dSumMinusTax;
   Â
    tabdata.Next();
    rowN++;
  }
}
The problem is I don't know how to catch the moment when page ends. I tried to go through ResultTable calculating and sum'ing row's heights and to make PageBreak when I'm out of FreeSpace, but each row had the same Height and CalcHeight even if visually rows were different. So this attemp failed. Also I tried using events of different bands such as PageFooter, DataBand and so on but with no success.
Do somebody have an idea how could I get sum per page in my case?
Comments
Thanks for reply. Your example gave me an idea, but when I try to code it I face a problem which is Report.GetVariableValue("Page") returns 1 everytime.
I think it's because of my table is dynamic and events might work some different way.
I've rewritten my report, filled it with fish-data and removed some useless stuff.
Could you check it? You'll see the problem because I've put the page number into Text1.
At first I thought it was necessary to use ManualBuild to build a table each column of which would stretch horizontally when some free space is on the page. Because it was shown in Fastreport's demo and I faced a lot of trouble. But at the end after I studied your example more carefully and read this "i give up with your approach [img]style_emoticons/<#EMO_DIR#>/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> " I decided not to use ManualBuild and tried another approach. And you know it worked) It might be not very beatifull cause there is some hardcode coupling interface and logic but it works and could be used as start point for somebody who needs the same report. P.S. It would be great if FR team made some "cookbook" or provide "Class Reference" manual with some examples because it's really very few information about fastreport on internet and existing manuals are not enough if you want to do something not trivial.[/img]