Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: crystal report viewer parameter field info null? Post Reply Post New Topic
Author Message
gphreak
Newbie
Newbie


Joined: 14 Mar 2007
Online Status: Offline
Posts: 17
Quote gphreak Replybullet Topic: crystal report viewer parameter field info null?
    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!
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet 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>
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.