I am trying to run some sample code and it seems that the parameter field info for my report viewer control always returns null and I get a runtime error.
using
System;
using System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
System.Collections;
using
CrystalDecisions.Shared;
namespace
WindowsApplication1
{
public partial class Form1 : Form
{
private const string PARAMETER_FIELD_NAME = "City";
public Form1()
{
InitializeComponent();
}
private void ConfigureCrystalReports()
{
string reportPath = Application.StartupPath + "\\" + "CustomersByCity.rpt";
ArrayList arrayList = new ArrayList();
arrayList.Add(
"Paris");
arrayList.Add(
"Tokyo");
ParameterFields parameterFields = crystalReportViewer1.ParameterFieldInfo;
SetCurrentValuesForParameterField(parameterFields, arrayList);
}
private void Form1_Load(object sender, EventArgs e)
{
ConfigureCrystalReports();
}
private void SetCurrentValuesForParameterField(ParameterFields parameterFields, ArrayList arrayList)
{
ParameterValues currentParameterValues = new ParameterValues();
foreach (object submittedValue in arrayList)
{
ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
parameterDiscreteValue.Value = submittedValue.ToString();
currentParameterValues.Add(parameterDiscreteValue);
}
ParameterField parameterField = parameterFields[PARAMETER_FIELD_NAME];
parameterField.CurrentValues = currentParameterValues;
}
}
}
Why does this happen? I was doing a tutorial from MSDN and I think the book code samples are similar to this, as well, yet I get that null. How do I fix this?
Thanks!