jeshbr
asked on
Subreports
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
TIA
Mike
ASKER
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].To String();
Report.OpenSubreport(lcSub Report).Lo ad(this.Ge tReportPat h() + "rptFeeReportSub1.rpt");
// Set the data source
if (SubReportDataSources != null)
Report.Subreports[lcSubRep ort].SetDa taSource(S ubReportDa taSources[ liSubRepor t]);
// Load the parameters for this sub report
if (SubReportParameters != null)
{
for (int liSRParameter = 0;
liSRParameter < SubReportParameters[liSubR eport].Get Length(0);
liSRParameter++)
{
lcParameter = SubReportParameters[liSubR eport][liS RParameter , 0].ToString();
ParameterValues lpvValues = new ParameterValues();
ParameterDiscreteValue lpdvParameter = new ParameterDiscreteValue();
lpdvParameter.Value = SubReportParameters[liSubR eport][liS RParameter , 1];
lpvValues.Add(lpdvParamete r);
Report.Subreports[lcSubRep ort].DataD efinition.
ParameterFields[lcParamete r].ApplyCu rrentValue s(lpvValue s);
}
}
}
But after it's all said and done the parameter values and data source for the main and subreport are wrong.
// Set the data source for the sub reports
for (int liSubReport = 0; liSubReport < SubReports.Count; liSubReport++)
{
lcSubReport = SubReports[liSubReport].To
Report.OpenSubreport(lcSub
// Set the data source
if (SubReportDataSources != null)
Report.Subreports[lcSubRep
// Load the parameters for this sub report
if (SubReportParameters != null)
{
for (int liSRParameter = 0;
liSRParameter < SubReportParameters[liSubR
liSRParameter++)
{
lcParameter = SubReportParameters[liSubR
ParameterValues lpvValues = new ParameterValues();
ParameterDiscreteValue lpdvParameter = new ParameterDiscreteValue();
lpdvParameter.Value = SubReportParameters[liSubR
lpvValues.Add(lpdvParamete
Report.Subreports[lcSubRep
ParameterFields[lcParamete
}
}
}
But after it's all said and done the parameter values and data source for the main and subreport are wrong.
ASKER
The Load() fails by the way!
it fails because when you open the sub report, you try to load
Create a reportdocument variable mysubreport and write this
MySubReport = MyReport.OpenSubreport(MyS ubReportOb ject.Subre portName)
Create a reportdocument variable mysubreport and write this
MySubReport = MyReport.OpenSubreport(MyS
ASKER
Even if I do that though it won't let me load it, it gives me this error...Not supported in subreports
Look at this code. This code works.I have done this , You have to cast the object first
CrystalDecisions.CrystalRe ports.Engi ne.ReportD ocument MySubReport;
CrystalDecisions.CrystalRe ports.Engi ne.Subrepo rtObject MySubReportObject;
foreach (CrystalDecisions.CrystalR eports.Eng ine.Report Object MyReportObject in MyReport.ReportDefinition. ReportObje cts)
{
if (MyReportObject.Kind == CrystalDecisions.Shared.Re portObject Kind.Subre portObject )
{
MySubReportObject = (CrystalDecisions.CrystalR eports.Eng ine.Subrep ortObject) MyReportOb ject;
if (MySubReportObject.Subrepo rtName != _subreportname)
{
if (this.ReportName == "InvestigationReport_Cover Page")
{
int i;
MySubReport = MyReport.OpenSubreport(MyS ubReportOb ject.Subre portName);
setlogoninfo(MySubReport);
SubReportName = MySubReportObject.Subrepor tName;
//this.SubReportDocument.A dd(MySubRe port);
if (MySubReportObject.Subrepo rtName == "InvestigationReport_Vehic les.rpt")
{
i = 1;
}
else
{
i = 0;
}
SetReportParameters_Invest igationRep ort(MySubR eport,i);
CrystalDecisions.CrystalRe
CrystalDecisions.CrystalRe
foreach (CrystalDecisions.CrystalR
{
if (MyReportObject.Kind == CrystalDecisions.Shared.Re
{
MySubReportObject = (CrystalDecisions.CrystalR
if (MySubReportObject.Subrepo
{
if (this.ReportName == "InvestigationReport_Cover
{
int i;
MySubReport = MyReport.OpenSubreport(MyS
setlogoninfo(MySubReport);
SubReportName = MySubReportObject.Subrepor
//this.SubReportDocument.A
if (MySubReportObject.Subrepo
{
i = 1;
}
else
{
i = 0;
}
SetReportParameters_Invest
ASKER
What does the code behind SetReportParameters_Invest igationRep ort() look like?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.CrystalRe
CrystalDecisions.Shared.Pa
CrystalDecisions.Shared.Pa
int paramcount;
paramcount = this.MyParameterValues.Cou
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.
if (ConversionVariable == "StoreProcedureParameter")
{
ParameterFieldDefinition = MyReport.DataDefinition.Pa
ParameterValues = new CrystalDecisions.Shared.Pa
ParameterDiscreteValue = new CrystalDecisions.Shared.Pa
ParameterDiscreteValue.Val
ParameterValues.Add(Parame
ParameterFieldDefinition.C
ParameterFieldDefinition.D
ParameterFieldDefinition.A
}
}
return ParameterFieldDefinition;