Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Increasing/Decreasing decimals and other problems Post Reply Post New Topic
Author Message
Marina
Newbie
Newbie


Joined: 16 Dec 2010
Location: Ukraine
Online Status: Offline
Posts: 2
Quote Marina Replybullet Topic: Increasing/Decreasing decimals and other problems
    Posted: 16 Dec 2010 at 11:52pm
Hello,
I'm very new to Crystal reports and currently have faced the following problems. I would much appreciate if someone helps, because googling didn't open my eyes.

Firstly, my task is to have buttons that increase/decrease decimals on reports.
I have implemented the following:
GetFieldObject to process like this:
ReportDocumentTypeOfReport rep= crystalReportViewer_.ReportSource as ReportDocumentTypeOfReport;
(FieldObject)rep.ReportDefinition.Sections["DetailSection1"].ReportObjects["PortRetD1"].NumberFormat.DecimalPlaces = 10;

Change numberFormat for it, then refresh like:
crystalReportViewer_.ReportSource = rep;
Everything worked like a clock!
The problems started with SubReports.

If i have a subreport within my report (some of its data including numbers is shown when main report is shown). When i access subreports fields and change numberformat:
ReportDocument
 irscrReport = report.Subreports["IRCSRReport"];
(FieldObject)irscrReport.ReportDefinition.Sections["DetailSection1"].ReportObjects["P"].NumberFormat....

(and refresh) nothing happens. When i go to that subreport, i can see that the decimals actually increased. But still no changes on the main report.
Is there a way to refresh subreport?

Also, I have not found a way to determine if i'm in a subreport to select it after i change decimals, because right now i'm switched to the main report.

Any help is MUCH appreciated (the deadline for the task is close).
Marina
IP IP Logged
Isak
Newbie
Newbie


Joined: 25 Mar 2010
Online Status: Offline
Posts: 6
Quote Isak Replybullet Posted: 17 Dec 2010 at 12:27pm
For some reason accessing the Subreports that way (report.SubReports) doesn't seem to do anything.

Here is how you can get at all the ReportObjects in a report, and change them:



private static List<ReportObject> GetAllReportObjects(ReportClass crReportDocument, List<ReportDocument> listReportDocumentsToCloseAndDispose)
{
    List<ReportObject> listAllReportObjects = new List<ReportObject>();            

    Queue<ReportDefinition> queueReportDefinitions = new Queue<ReportDefinition>();
    queueReportDefinitions.Enqueue(crReportDocument.ReportDefinition);            

    while (queueReportDefinitions.Any())
    {
        ReportDefinition reportDefinition = queueReportDefinitions.Dequeue();

        foreach (ReportObject reportObject in reportDefinition.ReportObjects)
        {
            if (reportObject.Kind == ReportObjectKind.SubreportObject)
            {
               SubreportObject subreportObject = (SubreportObject)reportObject;
               ReportDocument rdSubReport = subreportObject.OpenSubreport(subreportObject.SubreportName);                        
               queueReportDefinitions.Enqueue(rdSubReport.ReportDefinition);
               listReportDocumentsToCloseAndDispose.Add(rdSubReport);
            }
            else
               listAllReportObjects.Add(reportObject);
        }
    }
    return listAllReportObjects;
}

So you access the SubReports through the ReportObjects. The list you pass in is so you can close and Dispose the SubReport ReportDocuments after you customize the report objects (a little awkward, I know).

Here is what some client code could look like:

List<ReportDocument> listReportDocumentsToCloseAndDispose = new List<ReportDocument>();
List<ReportObject> listAllReportObjects = GetAllReportObjects(crReportDocument, listReportDocumentsToCloseAndDispose);

foreach (ReportObject reportObject in listAllReportObjects)
   CustomizeReportObject(reportObject);

foreach (ReportDocument reportDocument in listReportDocumentsToCloseAndDispose)
{
    reportDocument.Close();
    reportDocument.Dispose();
}

IP IP Logged
Marina
Newbie
Newbie


Joined: 16 Dec 2010
Location: Ukraine
Online Status: Offline
Posts: 2
Quote Marina Replybullet Posted: 22 Dec 2010 at 12:11am
Hello, Isak,
Thanks for the post. Unfortunately, it didn't change my situation at all :(
Subreports on main report view are not refreshed.
IP IP Logged
Isak
Newbie
Newbie


Joined: 25 Mar 2010
Online Status: Offline
Posts: 6
Quote Isak Replybullet Posted: 03 Jan 2011 at 5:24am
Strange, it is working for me. Though I'm doing pdf exports, so maybe you need something else if you're using the viewer.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.