Search Results for

    Show / Hide Table of Contents

    Example 6. Using the data source

    In all the examples considered, we printed a table, which contains an ordinary text. In this example we will show how to form a table using data source. For this, we will create a table having the following form:

    We will create the ManualBuild event handler, which will be doing the following:

    • get the data source, defined in the report;
    • initialize it (fill it with data);
    • print the table's rows as many times as there are rows in the data source.

    Here is the code of the handler:

    private void Table1_ManualBuild(object sender, EventArgs e)
    {
      // get the data source by its name
      DataSourceBase rowData = Report.GetDataSource("Products");
      // initialize it
      rowData.Init();
    
      // printing the table header
      Table1.PrintRow(0);
      Table1.PrintColumns();
    
      // loop through the data source rows
      while (rowData.HasMoreRows)
      {
        // printing the table row 
        Table1.PrintRow(1);
        Table1.PrintColumns();
    
        // select the next data row
        rowData.Next();
      }
    
      // printing the table footer
      Table1.PrintRow(2);
      Table1.PrintColumns();
    }
    

    If we run the report, we will get the following:

    Back to top © 1998-2025 Copyright Fast Reports Inc.