How to hide columns in a list if there is no data
When making the report, we want it to be "friendly" to the consumers as much as possible. Too much data and design elements processing makes people's understanding of information more unfavourable. As a result, many people want to delete spaces in a table without data. FastReport.Net report generator allows you to perform this function. As you understand, it is necessary not only to hide the column, but also a title for it. If hiding a column is a matter of a couple of clicks with a mouse, then hiding the title task is not trivial.
Suppose we have a table from which we want to display the data in a report. However, some data may be missing or set to zero. In this case, we can use the “Conditional Selection” tool to hide zero-data cells. Select the desired cell and click on the icon on the toolbar:
When you add conditions, by default there will be a check for zero. That is what we need. We only select display options. In our case, we remove the flag visible:
Therefore, these non-ingenious operations, we have realized a hidden zero-data cells. But that doesn't solve all the problems. Our task is to hide the title of the entire column if no value is greater than zero. The gap in this column will check the output of each page.
To check that there is no data on the page in a given column, we'll use the “result”.
This result is summed up by a given column and summarizes all the values in it. If the total is zero, then there is not a single value in the column more than zero, and you need to hide the column's header.
So. Let's add the result:
The result put in the band "Page Footer":
The result can then be hidden using the “visible” property.
Now let's set the logic to hide the headline of the last column. Instead of the RUB text, we introduce the expression:
[IIf([Total]!=0,Text14.Text = "RUB",Text14.Text = "")]
However, that is not all. Since the result is formed after the title and data are displayed on the page, at the time of execution of expression that we have introduced above, total value is not relevant. Therefore, we need to use the deferred expression calculation option in the column header and double pass on the report.
Choose a text box with the RUB column header. In the properties of the text field we find ProcessAt and change to PageFinished:
After this we need to open report properties and install “Doublepass” option:
This option allows you to build a report twice. In the first construction will be calculated all the results, and in the second one these results can be used in the headlines. All this is necessary, because the report is built elementally consistently. That is, when building the next element, you will not be able to change the previous one. Therefore, you need a re-build that takes into account the results of the next elements.
Let's see how our report works in terms of when all the data in the RUB column is 0:
On some pages the data can appear so the column will appear as well:
This way we can dynamically display or hide the columns according to the data in them.