CR .NET Runtime Customization

G

Guest

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

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 rptSamp

/// <summary
/// Summary description for Form1
/// </summary
public class Form1 : System.Windows.Forms.For

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 suppor
/
InitializeComponent()
/
// TODO: Add any constructor code after InitializeComponent cal
/


/// <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 cod
/// <summary
/// Required method for Designer support - do not modif
/// 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()
//
// textBox
//
this.textBox1.Location = new System.Drawing.Point(0, 0)
this.textBox1.Name = "textBox1"
this.textBox1.TabIndex = 0
this.textBox1.Text = ""
//
// button
//
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)
//
// viewer
//
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
//
// label
//
this.label1.BackColor = System.Drawing.SystemColors.Desktop
this.label1.Location = new System.Drawing.Point(184, 0)
this.label1.Name = "label1"
this.label1.TabIndex = 3
//
// Form
//
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 Name";
discValue.Value = "Rapel";
paramField.CurrentValues.Add (discValue);

paramFields.Add(paramField);

viewer1.ParameterFieldInfo = paramFields;
viewer1.RefreshReport();

}
}
}
 
G

Guest

Your code works just fine - provided that the parameter name is correct (check for spaces and tabs!)

But be carefull: if use parameters with default values in your report, than you will loose them

Hans
 
G

Guest

i still get the parameter prompt...how do i prevent that? I've checked the parameter name and still... I've changed the name of the parameter to "Product". so the code is -- paramField.ParameterFieldName = "Product"; I even tried paramField.ParameterFieldName = "?Product"; My selection fotmula looks like this --{Product.Product Name} = {?Product
What could be wrong? Thanks..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top