关闭

编程更改公式字段示例代码

1154人阅读 评论(0) 收藏 举报

以下是编程更改报表上公式字段的示例,此处假设已有CrystalReportAnalysis.rpt文件,其上放置有一个Name为Group的公式字段!

using CrystalDecisions.CrystalReports.Engine;

namespace GMedicine
{
   /// <summary>
   /// FormGMedicine 的摘要说明。
   /// </summary>
   public class FormGMedicine : System.Windows.Forms.Form
   {
       private const string CR_PATH = @"../../RPTGMedicine.rpt";
       private const string FORMULA_FIELD_NAME = @"Group";
       private string[] FORMULA_FIELD_TEXT = {"{客户.国家和地区}", "{客户.城市}",
              "{客户.联系人职位}", "{客户.地区}"};

       private CrystalDecisions.Windows.Forms.CrystalReportViewer crvGMedicine;
       private GMedicine.RPTGMedicine rptGMedicine;
       private System.Windows.Forms.ComboBox cbxSelectGroup;
  
       private void FormGMedicine_Load(object sender, System.EventArgs e)
       {
           LoadFormulaList();

           crvGMedicine.ReportSource = rptGMedicine;

           crvGMedicine.RefreshReport();
       }

       private void cbxSelectGroup_SelectedIndexChanged(object sender, System.EventArgs e)
       {
           FormulaFieldDefinition formulaField;

           formulaField = GetFormulaField(rptGMedicine, FORMULA_FIELD_NAME);

           formulaField.Text = cbxSelectGroup.SelectedItem.ToString();

           crvGMedicine.RefreshReport();
       }
  
       private FormulaFieldDefinition GetFormulaField(ReportDocument Report, string formulaFieldName)
       {
           FormulaFieldDefinition formulaField;

           // 按名称获取 FormulaFieldDefinition,
           //并返回此对象。
           formulaField = Report.DataDefinition.FormulaFields[formulaFieldName];
           if (formulaField != null) return formulaField;
           else return null;
       }
  
       private void LoadFormulaList()
       {
           foreach (string formula in FORMULA_FIELD_TEXT)
           {
              cbxSelectGroup.Items.Add(formula);
           }
       }
   }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:54605次
    • 积分:745
    • 等级:
    • 排名:千里之外
    • 原创:18篇
    • 转载:4篇
    • 译文:0篇
    • 评论:30条
    最新评论