Skip to main content Skip to footer

How to set runtime field values, set pagebreaks, and hide duplicate values in FlexReport

FlexReport has become a popular, lightweight .NET reporting tool for ComponentOne users. Like with any tool, users often face similar problems that seem difficult to fix in the moment. We're going to look at three common support issues for FlexReport.

1. Set field values at runtime

2. Set a report to have pagebreaks after each group

3. Hide duplicate values using the FlexReport Designer

1. Set field values at runtime

You may need to assign runtime values to report fields created using the FlexReport Designer--for instance, the field gets some value based on a condition or record in the code.

The solution is straightforward: Since the designer-created fields are added in the report's Fields collection, you'll need to directcast them to the particular field object that represents it in the report (TextField, ImageField, etc). Lastly, specify the value, and you're ready to go.

For example, in order to assign a value to the TextField at runtime, use this code:

C#

TextField newText = (TextField)c1FlexReport1.Fields["titleLbl"];
newText.Text = "Products Report";

VB

Dim newText As TextField = DirectCast(C1FlexReport1.Fields("titleLbl"), TextField)
newText.Text = "Products Report"

Here, the title “Products Report” gets its text at runtime:

Get field text at runtime

2. Set a report to have PageBreaks after each group

Sometimes, for the sake of clarity, it's best to have each report group on a new page--in other words, you need to set a PageBreak after each group.

Seems easy: set the ForcePageBreak property of the GroupFooter section to "After" / "PageAfter". But this generates an extra blank page at the end.

We can avoid this in two ways:

  • Set the ForcePageBreak property of the GroupHeader section to "Before" / "PageBefore"

  • Set the Visible property of GroupFooter and ReportFooter sections to false (in case you're not rendering anything in these sections).

Here, the second group (Category ID: 5) starts rendering from a new page, even though there's enough space left on the previous page:

Force page break

3. Hide duplicate values using FlexReport Designer

Duplicate values are often a nuisance in data sets; we usually don't want to see a long list of duplicates in a report. While FlexReport Designer has no direct setting, we can still hide duplicate values in the report.

  1. Go to VBScript Editor and select Script for 'Report.OnOpen' event. Declare a variable and call it "previousText".

    previousText = ""
    
  2. Select script 'Detail.OnPrint' in the same editor, and set this variable's value to the database column for which you want to hide the duplicates (in this case, 'CategoryID').

    previousText = CategoryID
    
  3. Set the Text property of the corresponding field as below (in this case, Field1).

    Iif(CategoryID= previousText ,"", CategoryID)
    

By testing for an existing instance of the text, we've eliminated the duplicate.

Eliminate duplicates

Let us know if these tips have been helpful, and include what else you'd like to see covered here!

Get the C# Code | Get the VB Code

Happy Reporting!

Esha Dhir

Associate Software Engineer
comments powered by Disqus