One of the subreports, SummaryCategoryMaster, contains a textbox and another subreport astCatDetailSubreport that has as it's ReportSource: SummaryCategoryDetail. SummaryCategoryDetail contains two text boxes. On one of these textboxes, textBox1, I've hooked an item data binding event that increments a public member _filteredCount, as follows:
public
int _filteredCount = 0;
private void textBox1_ItemDataBinding(object sender, EventArgs e)
{
_filteredCount += 1;
}
The intent here is to count how many rows will be added based on the filter. This seems to work fine and _filteredCount is set correctly based on the data that I supply to it.
In SummaryCategoryMaster, I have added the following event handler:
private void astCatDetailSubreport_ItemDataBound(object sender, EventArgs e)
{
SummaryCategoryDetail detailReport = (SummaryCategoryDetail)this.astCatDetailSubreport.ReportSource;
if (detailReport != null)
{
this.Visible = detailReport._filteredCount > 0;
detailReport._filteredCount = 0;
}
}
The intent is for the SummaryCategoryMaster subreport to not display if it's subreport has no data. When I run the code and display the report in a ReportViewer on a WinForm, however, the SummaryCategoryMaster appears no matter what the value to this.Visible is set to. When I save the generated report as a PDF, however, the SummaryCategoryMaster does not appear. I'm using the 430 version of 2009.
What am I doing wrong and is there a better way for me to do this?
Thanks in advance.