Print Page | Close Window

crystal report viewer parameter field info null?

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=326
Printed Date: 05 May 2024 at 11:23am


Topic: crystal report viewer parameter field info null?
Posted By: gphreak
Subject: crystal report viewer parameter field info null?
Date Posted: 14 Mar 2007 at 6:16pm
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!



Replies:
Posted By: BrianBischof
Date Posted: 14 Mar 2007 at 8:59pm
Have you checked that the report object has been assigned to the viewer object when you try to reference the parameter? It appears that you create the report path, but then you don't do anything with it. Use the Load() method to load it into memory and then see if you get your report parameters assigned.

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>



Print Page | Close Window