代码之家  ›  专栏  ›  技术社区  ›  HasanG Joe Dabones

如何在crystal report中以编程方式编辑标签?

  •  3
  • HasanG Joe Dabones  · 技术社区  · 14 年前

    我正在设计帐单报表,因此需要显示公司详细信息、日期时间和其他一些无法从数据源获取的信息。

    3 回复  |  直到 14 年前
        1
  •  2
  •   Kangkan    14 年前

    通常,对于账单,公司名称和详细信息(如地址等)显示在账单顶部。在这种情况下,我使用的是报告头。在这种情况下,您可以传递要显示的文本。在运行时传递内容的另一种方式是使用report参数。可以将参数绑定到字段或公式。参数也很容易传递。

    有一次,我使用以下代码从报表中动态获取参数并将其绑定到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;
        }
    

    并使用以下代码段设置参数:

        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
  •  3
  •   Will Marcouiller    14 年前

    Label FomulaField 然后可以通过 FormulaFieldDefinitions 收藏,你将与 FormulaFieldDefinition 为您感兴趣的类对象。

        3
  •  0
  •   Brownman98    14 年前