Skip to Content
author's profile photo Former Member
Former Member

Programmaticaly set default values for filter params in C#

Hi

In my application i would like to programmatically (in C#) set default values for parameters/ report filters. The user should then be able to choose a different report parameter if he needs to. (for example: set the start date to today if some critera is met)

However, if i do his in code, the parameter filter is no longer displayd when the report is shown. It seems to me that crystal reports assumes that the value for the filter parameter is already set. However, i just want to set the value that is shown in the filter control, the user should be able to choose a different filter value.

Is it possible in crystal reports to set the default value programmatically (in C#)???

Greetings

I am using:

Crystal Reports 2008

Version .NET 3.5 (SP1)

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Nov 19, 2008 at 07:29 PM

    Hello, Daniel;

    Are you using Crystal Reports Basic for Visual Studio .NET 2008 (10.5) or full Crysatl Reports Developer 2008 (12.0)

    Yes, you can set Default values at runtime. I found two examples for you:

    Check this SAP [Note|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes/sdn_oss_boj_erq/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes.do]

    There is also a Web or Windows application example called "CS_Web_RDObjMod_Parameters" or "CS_Win_RDObjMod_Parameters" in the tutorials:

    [Click Here|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b07a158a-b766-2b10-a79e-bfc6d19c6b99]

    This passes the default values to the ReportObject. How are you accessing the default values for your client? Are you using our viewer prompt?

    Elaine

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Eliane

      Thanks for your very helpfull support.

      We are using Crysatl Reports Developer 2008 (12.0).

      Previously, we tried to modify the default value as follows via the SetParameterValue method, but from the link you posted, i see now that this could never work.

      I changed my code as suggested and it works well for all non-dynamic filter values. Thank you very much.

      There are still some minor obstacles but i am working on it:

      -It seems to me that it is not possible to set default values if the filter params are dynamic (i recieve the following message: "Dynamic parameters cannot be modified...". ). Maybe it is possible to just select the first dynamic filter value that is found.

      - when i try to set start date programmatically, the gui adds a dropdown, with the default value but the actual date picker drop down, remains empty. I hope there is a solution for this.

      However, thank you very much for your support

      Daniel

  • author's profile photo Former Member
    Former Member
    Posted on Dec 01, 2008 at 03:18 PM

    Hi

    As i mentioned in my last post, i still have some problems with setting default filter parameter values programmatically. To set these default values, i use the following (or a similar) code snippet:

    private void SetCurrentValuesForParameterField(ReportDocument reportDocument, ArrayList arrayList)
    		{
    			ParameterValues currentParameterValues = new ParameterValues();
    			foreach (object submittedValue in arrayList)
    			{
    				ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
    				parameterDiscreteValue.Value = submittedValue.ToString();
    				currentParameterValues.Add(parameterDiscreteValue);
    
    			}
    			ParameterFieldDefinitions parameterFieldDefinitions = reportDocument.DataDefinition.ParameterFields;
    			ParameterFieldDefinition parameterFieldDefinition = parameterFieldDefinitions[PARAMETER_FIELD_NAME];
    			parameterFieldDefinition.ApplyCurrentValues(currentParameterValues);
    		}

    In most cases, this works fine. However, the following issues remains:

    - no default value can be set dynamic filter params. This is ok for me(us): However, it would be nice, if one could just choose the first retrieved dynamic value as default value. However, this is not a high priority task for us.

    - Setting default values for dates seems to work a bit strange. Having set a default value programmatically, an additional dropdown appears where one can choose the passed default value. This is not what we would like to have. We would rather have the default value being set in the date textbox. Is this somehow possible?

    Greetings and thanks in advance.

    Daniel

    Add a comment
    10|10000 characters needed characters exceeded

    • Don't use the Add method and use this one:

      reportClientDocument.DataDefController.ParameterFieldController.SetCurrentValue("", @"Your Parameter Name", @"Your Parameter Value");

      Using the Add method adds a new parameter which will fail because thename already exists.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.