This is a migrated thread and some comments may be shown as answers.

Hiding subreport problem...

4 Answers 260 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 01 May 2009, 04:31 PM
I have a Master report that contains two subreports.

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.

 

 

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 04 May 2009, 11:45 AM
Hello John,

You should use the processing report when in the context of event i.e.:

 private void subReport1_ItemDataBound(object sender, EventArgs e) 
        { 
            Processing.SubReport subReport = (Processing.SubReport)sender; 
        Processing.Report detailReport = (Processing.Report)subReport.InnerReport; 
            Processing.Report mainReport = (Processing.Report)subReport.Report; 
            mainReport.Visible = detailReport._filteredCount > 0; 
        } 

Also you do not need to count the detail rows like that unless you're using the count in other part of your logic. If it is only for the purpose of identifying when there is no data, you can do this much easier like so:

mainReport.Visible = detailReport.ChildElements.Find("detail", true).Length > 0;

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
John
Top achievements
Rank 1
answered on 04 May 2009, 12:36 PM

Hi Steve -
Thanks for the reply.  I had tried something very similar over the weekend, but your suggestion was far more elegant. Unfortunately, it's not producing the desired result.  Let me explain my problem with a little more detail.

My master report call it MasterReport contains a subreport SummaryMaster.  SummaryMaster consists of a group header (non-bounded) and a detail section (call it "detail").  "detail" contains a textbox ("textbox6") which displays a header and another subreport "SummaryDetail".  "SummaryDetail" will repeat for each detail row in a List<> collection in the datasource for SummaryMaster.   The SummaryMaster will repeat for each detail row contained in another List<> collection in MasterReport where it's bound.  Everything works great.  I'm now trying to prevent certain SummaryMaster's from appearing IF they have no data in their SummaryDetail subreports.

Currently, I get a SummaryMaster subreport with the header (textbox6) appearing and an empty SummaryDetail. What I want is the SummaryMaster subreport  skipped completely, when it's corresponding SummaryDetail has no data.

When I add this event handler in the SummaryMasterReport.cs:

 private void SummaryDetailSubreport_ItemDataBound(object sender, EventArgs e)  
 {  
   Processing.SubReport subReport = (Processing.SubReport)sender;  // I'm assuming this is SummaryDetail subreport
   Processing.Report detailReport = (Processing.Report)subReport.InnerReport;  // I'm assuming this is SummaryDetail Report
   Processing.Report mainReport = (Processing.Report)subReport.Report;  // I'm assuming this is SummaryMaster report
   mainReport.Visible = detailReport.ChildElements.Find("detail", true).Length > 0;  // Make containing SummaryMaster report invisible
 } 

the net effect is that when the MasterReport gets rendered, I see NO SummaryMaster reports at all, even though when I step through the code I verified that the mainReport.Visible is being set correctly depending on whether the subreport has data or not. I don't understand why all SummaryMaster reports become "invisible".

Thanks in advance for any advice or help you can offer on what I'm doing wrong or how I can get this to work.

... john ...
0
Steve
Telerik team
answered on 06 May 2009, 03:55 PM
Hi John,

We would appreciate if you modify the attached project to exhibit the problematic behavior you've encountered. Open a support ticket and attach the modified version or a sample project of your own. Once we review it, we would be able to provide you with more info.

Sincerely yours,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
John
Top achievements
Rank 1
answered on 06 May 2009, 11:27 PM
Hi Steve -

I have modified the project and have submitted it via a support ticket.  Ticket is 210558

Thanks again for your help!

... john ...
Tags
General Discussions
Asked by
John
Top achievements
Rank 1
Answers by
Steve
Telerik team
John
Top achievements
Rank 1
Share this question
or