Resetting line number on each printed page shows last number of previous page

I want to print a line-number before each printed detail-line of a report, and reset that number to 1 on each new page.
Therefore I use a variable (xLineNumber) , set in the following code in my report (in VB.Net) :
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Drawing
Imports Microsoft.VisualBasic
Imports FastReport
Imports FastReport.Data
Imports FastReport.Dialog
Imports FastReport.Table
Imports FastReport.Barcode
Imports FastReport.Utils

Namespace FastReport
Public Class ReportScript
public xLineNumber as Integer

Private Sub PageHeader1_BeforePrint(ByVal sender As object, ByVal e As EventArgs)
xLineNumber = 0
End Sub

Private Sub Data1_BeforePrint(ByVal sender As object, ByVal e As EventArgs)
xLineNumber += 1
End Sub
End Class
End Namespace

Problem is, starting on page 2 and on all the following pages, my first line-number seems to be the last number of the previous page. (See PDF attached).
How can I avoid this?

Comments

  • edited 3:58AM
    you must set report 'double pass' = true to fix the problem

    first pass : detect rowNumber, make a correction if needed, put the result into list<int>
    final pass : just display from list<int>
      public class ReportScript
      {
        private List<int> list = new List<int>();   // at engine.firstpass, put rowNumber into list<int>
        private int counter = 0;                             // at engine.finalpass, counter for displaying from list<int>
        private int rowNumber = 0;                           // check page shifting before put rowNumber into list<int>
        private int previousPageNumber = 1;                  // check page shifting before put rowNumber into list<int>
    
        private void Text1_BeforePrint(object sender, EventArgs e)
        {
          if (Engine.FirstPass)
          {
            int currentPageNumber = (int)Report.GetVariableValue("Page");
            if (currentPageNumber != previousPageNumber)
            {
              previousPageNumber = currentPageNumber;
              list[list.Count - 1] = 1;
              rowNumber = 1;
            }
            rowNumber += 1;
            list.Add(rowNumber);
          }
          else
          {
            Text1.Text = list[counter].ToString();
            counter +=1;        
          }
        }
      }
    
        Private list As List(Of Integer) = New List(Of Integer)()
        Private counter As Integer = 0
        Private rowNumber As Integer = 0
        Private previousPageNumber As Integer = 1
    
        Private Sub Text1_BeforePrint(ByVal sender As Object, ByVal e As EventArgs)
            If Engine.FirstPass Then
                Dim currentPageNumber As Integer = CInt(Report.GetVariableValue("Page"))
    
                If currentPageNumber <> previousPageNumber Then
                    previousPageNumber = currentPageNumber
                    list(list.Count - 1) = 1
                    rowNumber = 1
                End If
    
                rowNumber += 1
                list.Add(rowNumber)
            Else
                Text1.Text = list(counter).ToString()
                counter += 1
            End If
        End Sub
    
  • edited 3:58AM
    Works indeed! Thanks.
    (Strange there is no system variable to achieve this...)

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.