FlexReport for WinForms
動的ページヘッダーの追加
レポートのカスタマイズ > 動的ページヘッダーの追加

This topic uses "Dynamic Page Header" report to demonstrate how to generate page header dynamically.

状況に応じてレポートのページごとに異なるページヘッダーを表示する動的ページヘッダーを生成したい場合があります。それには、PageHeader の OnFormat プロパティを使用します。

たとえば、レポートの偶数ページと奇数ページに異なるレポートヘッダーを表示したいとします。This can be done with script that shows or hides sections depending on the page being rendered. In this report, the page header contains two sub-sections, one is used on odd pages and the other on even and their visibility is toggled using a script in the OnFormat property of PageHeader. Therefore, the page header section changes according to the current page number. The report also suppresses the page header on the first page by setting the Layout.PageHeader property to NotWithReportHdr. Perform the following steps to see how this can be done.

To create a report with dynamic page header

Step 1: Create a report

  1. Open the C1FlexReportDesigner and go to FILE|New.
  2. Click New Report drop down from the Reports tab and select Empty Report to create a report.
Back to Top

Step 2: Connect the report to a data source

  1. Switch to the Data tab, right-click the Main data source and choose Edit to open and the Data Sources Wizard and start editing.
  2. Select OLEDB Data Provider from the Data provider drop-down and click the ellipsis button next to the Connection string textbox to select the C1NWind.mdb file.
  3. Specify the following Sql statement in the Sql statement tab:
    SELECT Categories.*, Products.*
    FROM Categories INNER JOIN Products
    ON Categories.CategoryID = Products.CategoryID
    
Back to Top

Step 3: Change page header dynamically

  1. Right-click the PageHeader section and select Add SubSection so that you have PageHeader/<A> and PageHeader/<B>, one for odd pages and the other for even pages.
  2. In the subsections, add two text fields each and set their Text properties as shown in the tables below. The values set in the text property are the expressions for displaying the headers on odd and even pages.
    PageHeader/<A> properties Values
    TextField1.Text ="Page " & [Page] & " (ODD)"
    TextField2.Text =Now()

    PageHeader/<B> properties Values
    TextField3.Text =Now()
    TextField4.Text ="Page " & [Page] & " (EVEN)"

  3. Go to the OnFormat property of PageHeader and click the ellipsis next to it. The VBScript Editor appears.
  4. Enter the following VBScript expression in the editor:
    odd = (page mod 2 <> 0)
    PageHeader.SubSections(0).Visible = odd
    PageHeader.SubSections(1).Visible = not odd
    

  5. Click Groups in Home tab and add a group named CategoryName.
  6. In the Groups wizard, set the following properties for the CategoryName group:
    Property Value
    GroupBy CategoryName
    Keep Together KeepFirstDetail
    Sort Ascending
    ShowGroupFooter False
    ShowGroupHeader True
    OutlineLabel =CategoryName

  7. Click OK to close the Groups wizard.
  8. Right-click CategoryName_Header group and select Add SubSection from the context menu.
  9. Add two SubSections to the group header.
  10. In CategoryName_Header/<B> subsection, add a TextField and set its Text property to =CategoryName.
  11. In CategoryName_Header/<C> subsection, add four TextFields and set the following properties.
    Property Value
    TextField6.Text Product Name
    TextField7.Text Quantity Per Unit
    TextField8.Text Unit Price
    TextField9.Text In Stock

  12. In the Details section, add five TextFields corresponding to the TextFields in CategoryName_Header/<C>, and set the following properties:
    Property Value
    TextField10.Text =left(ProductName, 30)
    TextField11.Text =QuantityPerUnit
    TextField12.Text =UnitPrice
    TextField13.Text =UnitsInStock

  13. Select the report from the drop-down list on the top of the Properties window.
  14. Set the Layout.PageHeader property of the report to NotWithReportHdr to suppress the page header on first page of a report.
Back to Top

Step 4: View the report

Preview the report with dynamic page header.
Report with Dynamic Page Header

Back to Top

メモ: レポートの完全なサンプルについては、ComponentOne Samples\Winforms\C1FlexReport\CS\FlexCommonTasks フォルダにある FlexCommonTasks.flxr レポート定義ファイルの「Dynamic Page Header」レポートを参照してください。使用するデータベース C1NWind.mdb も、ComponentOne Samples フォルダにあります。