Kbase P145747: How to add the .NET Crystal Reports Viewer into a form?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  05/05/2009 |
|
Status: Unverified
GOAL:
How to add the .NET Crystal Reports Viewer control into a form?
GOAL:
Why isn't it possible to add CrystalReportViewer .NET controls to the Visual Designer, as well as some other controls of Crystal Reports?
FACT(s) (Environment):
Windows
OpenEdge 10.2x
FIX:
We intentionally filter the Crystal Reports controls from the toolbox and also do not let user to add these controls from Add controls dialog directly.
The issue comes from the hard-coded dependency the CrystalReportViewer .NET Control has with Visual Studio environment. Progress cannot fix the issue unless Crystal Report removes the dependency on Visual studio environment.
However it is still possible to achieve your goal using the using the Assembly References Tool to add the Crystal references.
Here are the steps:
- Save the new assemblies.xml file in the project root.
- Wrap the CR viewer as follows:
/* ReportViewer.cls */
USING Progress.Lang.*.
USING Progress.Windows.UserControl.
CLASS ReportViewer INHERITS UserControl :
DEFINE PRIVATE VARIABLE components AS System.ComponentModel.IContainer.
DEFINE PRIVATE VARIABLE crystalReportViewer1 AS CrystalDecisions.Windows.Forms.CrystalReportViewer NO-UNDO.
DEFINE PUBLIC PROPERTY ReportSource AS CHARACTER NO-UNDO
GET.
SET(INPUT arg AS CHARACTER):
ReportSource = arg.
crystalReportViewer1:ReportSource = arg.
END SET.
CONSTRUCTOR PUBLIC ReportViewer ( ):
SUPER().
InitializeComponent().
CATCH e AS Progress.Lang.Error:
UNDO, THROW e.
END CATCH.
END CONSTRUCTOR.
METHOD PRIVATE VOID InitializeComponent( ):
/* NOTE: The following method is generated by the OpenEdge Advanced GUI Visual Designer.
We strongly suggest that the contents of this method only be modified using the
Visual Designer to avoid any incompatible modifications.
Modifying the contents of this method using a code editor will invalidate any support for this file. */
THIS-OBJECT:crystalReportViewer1 = NEW CrystalDecisions.Windows.Forms.CrystalReportViewer().
THIS-OBJECT:SuspendLayout().
/* */
/* crystalReportViewer1 */
/* */
/* THIS-OBJECT:crystalReportViewer1:Anchor = CAST(Progress.Util.EnumHelper:Or(CAST(Progress.Util.EnumHelper:Or(CAST(Progress.Util.EnumHelper:Or(System.Windows.Forms.AnchorStyles:Top, System.Windows.Forms.AnchorStyles:Bottom), System.Windows.Forms.AnchorStyles), System.Windows.Forms.AnchorStyles:Left), System.Windows.Forms.AnchorStyles), System.Windows.Forms.AnchorStyles:Right), System.Windows.Forms.AnchorStyles). */
THIS-OBJECT:crystalReportViewer1:ActiveViewIndex = -1.
THIS-OBJECT:crystalReportViewer1:BorderStyle = System.Windows.Forms.BorderStyle:FixedSingle.
THIS-OBJECT:crystalReportViewer1:Dock = System.Windows.Forms.DockStyle:Fill.
THI.S-OBJECT:crystalReportViewer1:Location = new System.Drawing.Point(0, 0).
THIS-OBJECT:crystalReportViewer1:Name = "crystalReportViewer1".
THIS-OBJECT:crystalReportViewer1:SelectionFormula = "".
THIS-OBJECT:crystalReportViewer1:Size = new System.Drawing.Size(420, 320).
THIS-OBJECT:crystalReportViewer1:TabIndex = 0.
THIS-OBJECT:crystalReportViewer1:ViewTimeSelectionFormula = "".
/* */
/* ReportViewer */
/* */
/* THIS-OBJECT:AutoScaleDimensions = NEW System.Drawing.SizeF(6, 13). */
THIS-OBJECT:AutoSize = TRUE.
THIS-OBJECT:BackColor = System.Drawing.SystemColors:Desktop.
THIS-OBJECT:Controls:Add(THIS-OBJECT:crystalReportViewer1).
THIS-OBJECT:Name = "ReportViewer".
THIS-OBJECT:Size = NEW System.Drawing.Size(300, 300).
THIS-OBJECT:ResumeLayout(FALSE).
CATCH e AS Progress.Lang.Error:
UNDO, THROW e.
END CATCH.
END METHOD.
DESTRUCTOR PUBLIC ReportViewer ( ):
IF VALID-OBJECT(components) THEN DO:
CAST(components, System.IDisposable):Dispose().
END.
END DESTRUCTOR.
END CLASS.
/* end of ReportViewer.cls */
- In order to be able to see the Crystal Reports Viewer in the Visual Designer, create a Form and add the following code to it:
DEFINE VARIABLE crystalReportViewer1 AS
CrystalDecisions.Windows.Forms.CrystalReportViewer NO-UNDO.
crystalReportViewer1 = NEW
CrystalDecisions.Windows.Forms.CrystalReportViewer().
crystalReportViewer1:ActiveViewIndex = -1.
crystalReportViewer1:BorderStyle =
System.Windows.Forms.BorderStyle:FixedSingle.
crystalReportViewer1:Dock = System.Windows.Forms.DockStyle:Fill.
crystalReportViewer1:Location = new System.Drawing.Point(0, 0).
crystalReportViewer1:Name = "crystalReportViewer1".
crystalReportViewer1:SelectionFormula = "".
crystalReportViewer1:Size = new System.Drawing.Size(420, 320).
crystalReportViewer1:TabIndex = 0.
crystalReportViewer1:ViewTimeSelectionFormula = "".
Controls:Add(crystalReportViewer1).
.