How to programmatically edit a label in a crystal report?

I have a Crystal Reports report and I want to edit the label programmatically from C #. I can manipulate the data source, but I cannot edit the label.

I am compiling a statement of account, so I need to display information about the company, date and other information that I can not get from my data source.

+3
source share
3 answers

Usually for an account where the name of the company and its details (for example, address, etc.) are displayed at the top of the account. In this case, I use the report title. In this case, you can easily convey the text to be displayed. Another way to pass something at runtime would be to use a report parameter. You can bind this parameter to a field or to a formula. The options are also very simple.

In one case, I used the following code to dynamically retrieve parameters from a report and bind it to a gridview:

    private void GetParameters()
    {
        //DataTable dt = new DataTable("Params");
        string dataTableName  = "Params";
        //add a tablestyle to the grid so there will be custom columnstyles available
        // after the datasource has been set....
        DataGridTableStyle ts = new System.Windows.Forms.DataGridTableStyle();
        ts.MappingName = dataTableName;
        dtgParams.TableStyles.Add(ts);

        // DataGridTextBoxColumn
        DataGridTextBoxColumn cParamName = new DataGridTextBoxColumn();
        cParamName.MappingName = "Parameter";
        cParamName.HeaderText = "Parameter";
        cParamName.ReadOnly=true;

        // Add the column style to the column style collection
        ts.GridColumnStyles.Add( cParamName );

        // DataGridTextBoxColumn
        DataGridTextBoxColumn cType = new DataGridTextBoxColumn();
        cType.MappingName = "Data_Type";
        cType.HeaderText = "Data Type";
        cType.ReadOnly=true;

        // Add the column style to the column style collection
        ts.GridColumnStyles.Add( cType );

        // DataGridTextBoxColumn
        DataGridTextBoxColumn cValue = new DataGridTextBoxColumn();
        cValue.MappingName = "Value";
        cValue.HeaderText = "Value";
        cValue.ReadOnly=false;

        // Add the column style to the column style collection
        ts.GridColumnStyles.Add( cValue );

        DataRow dr;
        dt.Columns.Add(new DataColumn("Parameter",typeof(string)));
        dt.Columns.Add(new DataColumn("Data_Type",typeof(string)));
        dt.Columns.Add(new DataColumn("Value",typeof(string)));

        // For all the Parameters defined in the report
        for(int i=0;i<ReportDoc.DataDefinition.ParameterFields.Count;  i++)
        {
            dr = dt.NewRow();
            dr[0] = ReportDoc.DataDefinition.ParameterFields[i].ParameterFieldName;
            dr[1] = ReportDoc.DataDefinition.ParameterFields[i].ParameterValueKind;
            dr[2] = ReportDoc.DataDefinition.ParameterFields[i].DefaultValues[0];
            dt.Rows.Add(dr);
        }
        DataView source = new DataView(dt);
        dtgParams.DataSource = source;
    }

And use the following code segment to set the parameters:

    private void SetParamValue  (string paramName, string paramValue)
    {
        ParameterFieldDefinition PFD = null;
        ParameterValues PValues = null;
        ParameterDiscreteValue Parm = null;
        PValues = new ParameterValues();
        PFD = ReportDoc.DataDefinition.ParameterFields[paramName];
        Parm = new ParameterDiscreteValue();
        Parm.Value = paramValue;
        PValues.Add(Parm);
        PFD.ApplyCurrentValues(PValues);
    }
+2
source

Label a FomulaField, FormulaFieldDefinitions, FormulaFieldDefinition, .

, .. , RPT. , .

+3

Source: https://habr.com/ru/post/1774165/


All Articles