I'm new to C# .Net and Crystal Reports for .Net.
(1) I'm having problems in setting parameter fields at runtime. I used the code at the msdn
documentation but it doesn't work for me. What I want to happen is to get the value of the
parameter supplied by the user through a textbox, instead of having the parameter dialog box
prompt the user for input. But the dialog box still pops up. What wrong with my code? (see below...)
Another thing is that the ParameterFieldName property (and the other properties such as
CurrentValues,MinimumValue,etc.) of the ParameterField Variable I declared is not available
for selection in the intellisense...it's replaced by set_ParameterFieldName/get_ParameterFieldName...(set_CurrentValues, etc.). How can I correct this?
(2) I published my report as a web service so I'm using the crystal report viewer in making
runtime customizations. Is there a way that I could use the report engine object model
instead, so I could have access to all the properties and methods needed to customize the
report in code?
I pasted my code below. Hope you can help me. Thanks.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
namespace rptSamp2
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private CrystalDecisions.Windows.Forms.CrystalReportViewer viewer1;
private System.Windows.Forms.Label label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.viewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(0, 0);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 0);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// viewer1
//
this.viewer1.ActiveViewIndex = -1;
this.viewer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.viewer1.Location = new System.Drawing.Point(8, 32);
this.viewer1.Name = "viewer1";
this.viewer1.ReportSource = "C:\\Inetpub\\wwwroot\\WebService1\\CrystalReport1.rpt";
this.viewer1.Size = new System.Drawing.Size(272, 232);
this.viewer1.TabIndex = 2;
//
// label1
//
this.label1.BackColor = System.Drawing.SystemColors.Desktop;
this.label1.Location = new System.Drawing.Point(184, 0);
this.label1.Name = "label1";
this.label1.TabIndex = 3;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.label1);
this.Controls.Add(this.viewer1);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[sTAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
ParameterFields paramFields = new ParameterFields();
ParameterField paramField= new ParameterField();
ParameterDiscreteValue discValue = new ParameterDiscreteValue();
paramField.ParameterFieldName = "Product";
discValue.Value = textBox1.text;
paramField.CurrentValues.Add (discValue);
paramFields.Add(paramField);
viewer1.ParameterFieldInfo = paramFields;
viewer1.RefreshReport();
}
}
}