1704605 - Parameter DefaultValue does not return a count from the Parameter collection

SAP Knowledge Base Article - Public

1704605 - Parameter DefaultValue does not return a count from the Parameter collection

Symptom

Getting default values from the report returns zero count.

Environment

Crystal Reports for Visual Studio 2010

Cause

This is a known issue and has been tracked as ADAPT01582063

Resolution

This issue has been addressed in Crystal Reports for Visual Studio 2010 Service Pack 3.
 
The follow code snippet returns the default values saved in the report file:

 
        if (rptClientDoc.DataDefController.DataDefinition.ParameterFields.Count > 0) //there are parameters
            {
                foreach (CrystalDecisions.ReportAppServer.DataDefModel.ParameterField paramfield in rptClientDoc.DataDefController.DataDefinition.ParameterFields)
                {
                    switch (paramfield.ValueRangeKind)
                    {
                        case CrParameterValueRangeKindEnum.crParameterValueRangeKindDiscrete:
                            {
                                getDiscreteValues(paramfield);
                                break;
                            }
                        case CrParameterValueRangeKindEnum.crParameterValueRangeKindDiscreteAndRange:
                            {
                                getRangeAndDiscreteValues(paramfield);
                                break;
                            }
                        case CrParameterValueRangeKindEnum.crParameterValueRangeKindRange:
                            {
                                getRangeValues(paramfield);
                                break;
                            }
                    }
                }
            }
 
        }
 
        private void getDiscreteValues(CrystalDecisions.ReportAppServer.DataDefModel.ISCRParameterField paramfield)
        {
            string textBox1 = String.Empty;
            string name = paramfield.Name;
            int currValCount = paramfield.InitialValues.Count;
            int defValCount = paramfield.DefaultValues.Count;
            if (currValCount > 0)  //this parameter has default values
            {
                foreach (ParameterFieldDiscreteValue discreteDefaultVal in paramfield.InitialValues)
                {
                    btnReportObjects.AppendText(paramfield.Name.ToString());
                    textBox1 = ": " + discreteDefaultVal.Value.ToString();
                    btnReportObjects.Text += textBox1;
                    btnReportObjects.AppendText("\n");
                    //MessageBox.Show(discreteDefaultVal.Value.ToString());
                }
            }
            else
            {
                btnReportObjects.AppendText(paramfield.Name.ToString());
                btnReportObjects.AppendText(": No Initial Value \n");
            }
        }
 
        private void getRangeValues(CrystalDecisions.ReportAppServer.DataDefModel.ParameterField paramfield)
        {
            string name = paramfield.Name;
            int currValCount = paramfield.CurrentValues.Count;
            //bool currDefCount = paramfield.;
            int defValCount = paramfield.DefaultValues.Count;
            //if (defValCount > 0)  //this parameter has default values
            try
            {
                foreach (ParameterFieldDiscreteValue discreteDefaultVal in paramfield.DefaultValues)
                {
                    MessageBox.Show(discreteDefaultVal.Value.ToString());
                }
            }
            catch
            { }
        }
 
        private void getRangeAndDiscreteValues(CrystalDecisions.ReportAppServer.DataDefModel.ParameterField paramfield)
        {
            string name = paramfield.Name;
            int currValCount = paramfield.CurrentValues.Count;
            int defValCount = paramfield.DefaultValues.Count;
            if (defValCount > 0)  //this parameter has default values
            {
                foreach (ParameterFieldRangeValue discreteDefaultVal in paramfield.DefaultValues)
                {
                    MessageBox.Show(discreteDefaultVal.BeginValue.ToString());
                }
            }
        }

Keywords

parameter default values, Crystal Reports for Visual Studio 2010 , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , Problem

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio