By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,008 Members | 2,963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,008 IT Pros & Developers. It's quick & easy.

Crystal Reports .NET - can't view a report more than once

P: n/a

I was trying to run a crystal report in the .net sample application
given at:

(I've reproduced the relevant file below.)

However, I want to view the report three times in a row.

I tried replacing:

Application::Run(new ViewForm());

at the end of the file with:
Application::Run(new ViewForm());
Application::Run(new ViewForm());
Application::Run(new ViewForm());

However, the second time Run() is called, the viewer comes up, then
disappears immediately. It works fine the third time. I checked, and
it works fine every odd time, and fails every even time.

Anyone have any idea what I'm doing wrong?

Thanks muchly,


//Created: March 27, 2002
//Author ID: TDU
//Purpose: This C++ .NET sample Windows application demonstrates
how to
// pass multiple values to a single discrete parameter
// using the engine object model.

//Both of these CR assemblies are required to be able to
//access, load, and set database logon.

#include "stdafx.h"

#using <mscorlib.dll>
#using <System.Windows.Forms.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <CrystalDecisions.Shared.dll>
#using <CrystalDecisions.Windows.Forms.dll>
#using <CrystalDecisions.CrystalReports.Engine.dll>

using namespace System;
using namespace System::Windows::Forms;
using namespace CrystalDecisions::Shared;
using namespace CrystalDecisions::CrystalReports::Engine;
using namespace CrystalDecisions::Windows::Forms;

// This is the main form that will hold the viewer control.
__gc class ViewForm : public System::Windows::Forms::Form
//Declare the Viewer Control, Report Document, and other
//objects needed to set the Parameter values.

CrystalDecisions::Windows::Forms::CrystalReportVie wer* crViewer;
ReportDocument* crReportDocument;
ParameterFieldDefinitions* crParameterFieldDefinitions;
ParameterFieldDefinition* crParameterFieldDefinition;
ParameterValues* crParameterValues;
ParameterDiscreteValue* crParameterDiscreteValue;

//Public constructor
InitForm() ;
this->Dispose() ;

void InitForm()
//This function initializes the form and adds the viewer to the
// Instantiate the viewer control and add it to the form
this->crViewer = new
CrystalDecisions::Windows::Forms::CrystalReportVie wer();
this->crViewer->ActiveViewIndex = -1;
this->crViewer->Dock = System::Windows::Forms::DockStyle::Fill;
this->crViewer->Name = "crystalReportViewer1";
this->crViewer->TabIndex = 0;
this->Controls->Add (this->crViewer);

//This attaches the form load event to the function.
this->Load += new System::EventHandler (this, ViewForm_Load);

void ViewForm_Load(System::Object* sender, System::EventArgs* e)
String* crParamVal;
//Instantiate the report and load the report.
crReportDocument = new ReportDocument ();
("C:\\Crystal\\crnet\\cppnet_win_paramengine\\CRPa rams.rpt");

//Get the collection of parameters from the report
crParameterFieldDefinitions =

//Access the specified parameter from the collection
crParameterFieldDefinition =
crParameterFieldDefinitions->Item ["Country"];

//Get the current values from the parameter field. At
this point
//there are zero values set.
crParameterValues = crParameterFieldDefinition->CurrentValues;

//Set the current values for the parameter field
crParamVal = "Canada";
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue->Value = crParamVal; //1st
current value

//Add the first current value for the parameter field

//Since this parameter allows multiple values, the
discrete value
//object needs to be reset. Destroy the previous instance
and create
//a new instance.
crParameterDiscreteValue = 0;
crParameterDiscreteValue = new ParameterDiscreteValue();

//Add the second current value for the parameter field
crParamVal = "USA";
crParameterDiscreteValue->Value = crParamVal; //2nd current value

//All current parameter values must be applied for the
parameter field.

//Set the viewer to the report object to be previewed.
crViewer->ReportSource = crReportDocument;

// This is the entry point for this application
#ifdef _UNICODE
int wmain(void)
int main(void)
Application::Run(new ViewForm());
return 0;
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.