Is it possible to register default parameters for ALL reports ?

lollol
edited 4:40AM in FastReport .NET
Hello,

I need to have two parameters always available in ALL my reports, so I was thinking if I did something I saw in an earlier thread the parameters would be available.

This is what I tried :

Parameter p = new Parameter("MyDate");
p.DataType = typeOf(DateTime)
Report.Dictionary.Parameters.Add(p)

(I thought adding to the Dictionary and not to the Parameters collection was the key issue, but it didn't worked)

This is what I had done before :

Parameter p = new Parameter("MyDate");
p.DataType = typeOf(DateTime)
Report.Parameters.Add(p);

The result is the same :

The parameter is available in the parameters section only when I open the designer after doing the addition, or when opening an old report (edition).

If I select the New menu item inside the designer, the new report has no parameters defined in the parameters section.

Is there any workaround for this ?

Thank you.

Luis

Comments

  • edited 4:40AM
    In v1.0.184 you will able to use the ReportLoaded event to do this. This event may be attached either to the EnvironmentSettings.DesignerSettings, or to its non-visual equivalent, Config.DesignerSettings. Here is an example:
    ...
    Config.DesignerSettings.ReportLoaded += new ReportLoadedEventHandler(DesignerSettings_ReportLoaded);
    AddPersistentParameters(report);
    report.Design();
    ...
    
    private void AddPersistentParameters(Report report)
    {
      // check if parameter already exists
      if (report.Parameters.FindByName("myParam") == null)
      {
        Parameter myParam = new Parameter("myParam");
        myParam.DataType = typeof(int);
        myParam.Value = 10;
        report.Parameters.Add(myParam);
      }
    }
    
    void DesignerSettings_ReportLoaded(object sender, ReportLoadedEventArgs e)
    {
      AddPersistentParameters(e.Report);
    }
    
  • lollol
    edited 4:40AM
    Sounds great.

    Thank you

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.