views:

957

answers:

1

How do i get subreport name in C# ?
i have one main report and one subreport.In my C# code i need to get the subreportName.

rptDynamicReport rpt = new rptDynamicReport();  // CrystalReport
//i need somethig like this
string reportName = "Multiple";// Where multiple is the sub report name
+3  A: 
using CrystalDecisions.CrystalReports.Engine;
//snip

//Where report is the parent rpt of type ReportDocument (or a subclass of ReportDocument)
foreach(ReportDocument subreport in rpt.Subreports)
{
    if(subreport.Name = "Multiple")
    {
        //Not the most elegant solution, but should work
        SubreportObject subrpt = (SubreportObject)subreport;
        subrpt.Height = 0;
    }
}

Per your request I have added the hiding functionality, I haven't tested this out and haven't done any hiding of subreports personally. I think that this should work. I couldn't find any "Visible" property or anything like that.

Nathan Koop
Thanks so much for ur answer..I tried..foreach(ReportDocument subreport in rpt.subreports){ if(subreport.Name = "Multiple") { //Do Something }}
Girish1984
Nathan i have one more question for you...How to hide or make visible false subreport if subreport.Name is Multiple ?
Girish1984
@Girish, what do you think of this revision
Nathan Koop
Cannot convert type 'CrystalDecisions.CrystalReports.Engine.ReportDocument' to 'CrystalDecisions.CrystalReports.Engine.SubreportObject'..I get this error
Girish1984
I had forgotten a portion of the foreach should be rpt.Subreports try that now
Nathan Koop