Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Subreports

Posted on 2004-07-30
9
Medium Priority
?
440 Views
Last Modified: 2008-02-01
We are trying to use a subreport, but now in Crystal Reports 10 we cannot use the Load() method or the SetParameterValue() method.  How am I supposed to get the DataSource and Parameters set for the subreport if I can't even load it!

TIA

Mike
0
Comment
Question by:jeshbr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 10

Expert Comment

by:ebolek
ID: 11678135
You can get a reference to the subreport from the main report by using

Opensubreport methoid then

You can use following code to set the parameetrs of the subreport. The report document is the referenced subreport from the open method

//sets the parameter values for main report and sub reports if any
                  CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition ParameterFieldDefinition;
                  CrystalDecisions.Shared.ParameterDiscreteValue  ParameterDiscreteValue;
                  CrystalDecisions.Shared.ParameterValues  ParameterValues;                              
                  int paramcount;
                  paramcount = this.MyParameterValues.Count;
                  ParameterFieldDefinition = null;
                  string ConversionVariable;
                  ConversionVariable = null;                  
                  for (int i = 0; i != paramcount; i++)//have to put paramcount otherwise hard code it .works
                  {
                        ConversionVariable = Convert.ToString(MyReport.DataDefinition.ParameterFields[i].ParameterType);  
                        if (ConversionVariable == "StoreProcedureParameter")       
                        {
                              ParameterFieldDefinition = MyReport.DataDefinition.ParameterFields[i];  
                              ParameterValues = new CrystalDecisions.Shared.ParameterValues();
                              ParameterDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();      
                              ParameterDiscreteValue.Value = this.MyParameterValues[i];      
                              ParameterValues.Add(ParameterDiscreteValue);
                              ParameterFieldDefinition.CurrentValues.Clear();
                              ParameterFieldDefinition.DefaultValues.Clear();  
                              ParameterFieldDefinition.ApplyCurrentValues(ParameterValues);
                        }
                  }
                  return ParameterFieldDefinition;
0
 
LVL 3

Author Comment

by:jeshbr
ID: 11678309
This is the code I currently have.

//      Set the data source for the sub reports
for (int liSubReport = 0; liSubReport < SubReports.Count; liSubReport++)
{
      lcSubReport = SubReports[liSubReport].ToString();
      Report.OpenSubreport(lcSubReport).Load(this.GetReportPath() + "rptFeeReportSub1.rpt");

      //      Set the data source
      if (SubReportDataSources != null)
            Report.Subreports[lcSubReport].SetDataSource(SubReportDataSources[liSubReport]);

      //      Load the parameters for this sub report
      if (SubReportParameters != null)
      {
            for (int liSRParameter = 0;
                  liSRParameter < SubReportParameters[liSubReport].GetLength(0);
                  liSRParameter++)
            {
                  lcParameter = SubReportParameters[liSubReport][liSRParameter, 0].ToString();

                  ParameterValues lpvValues = new ParameterValues();
                  ParameterDiscreteValue lpdvParameter = new ParameterDiscreteValue();
                  lpdvParameter.Value = SubReportParameters[liSubReport][liSRParameter, 1];

                  lpvValues.Add(lpdvParameter);

                  Report.Subreports[lcSubReport].DataDefinition.
                        ParameterFields[lcParameter].ApplyCurrentValues(lpvValues);
            }
      }
}

But after it's all said and done the parameter values and data source for the main and subreport are wrong.
0
 
LVL 3

Author Comment

by:jeshbr
ID: 11678317
The Load() fails by the way!
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 10

Expert Comment

by:ebolek
ID: 11678389
it fails because when you open the sub report, you try to load
Create a reportdocument variable mysubreport and write this
MySubReport = MyReport.OpenSubreport(MySubReportObject.SubreportName)
0
 
LVL 3

Author Comment

by:jeshbr
ID: 11678463
Even if I do that though it won't let me load it, it gives me this error...Not supported in subreports
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11678516
Look at this code. This code works.I have done this , You have to cast the object first

CrystalDecisions.CrystalReports.Engine.ReportDocument MySubReport;
                  CrystalDecisions.CrystalReports.Engine.SubreportObject MySubReportObject;
                  foreach (CrystalDecisions.CrystalReports.Engine.ReportObject MyReportObject in MyReport.ReportDefinition.ReportObjects)
                  {
                        if (MyReportObject.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
                        {
                              MySubReportObject = (CrystalDecisions.CrystalReports.Engine.SubreportObject)MyReportObject;
                              
                              if (MySubReportObject.SubreportName != _subreportname)
                              {
                                    if (this.ReportName == "InvestigationReport_CoverPage")
                                    {
                                          int i;
                                          MySubReport = MyReport.OpenSubreport(MySubReportObject.SubreportName);                               
                                          setlogoninfo(MySubReport);
                                          SubReportName = MySubReportObject.SubreportName;
                                          //this.SubReportDocument.Add(MySubReport);
                                          if (MySubReportObject.SubreportName == "InvestigationReport_Vehicles.rpt")
                                          {
                                                i = 1;
                                          }
                                          else
                                          {
                                                i = 0;
                                                
                                          }
                                          SetReportParameters_InvestigationReport(MySubReport,i);
0
 
LVL 3

Author Comment

by:jeshbr
ID: 11693864
What does the code behind SetReportParameters_InvestigationReport() look like?
0
 
LVL 10

Accepted Solution

by:
ebolek earned 1500 total points
ID: 11951665
SetReportParameters_InvestigationReport()  is the twisted version of the code that I posted

That code should help your problem

Regards
Emre
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question