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

类别:.NET开发 点击:0 评论:0 推荐:

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);
   }
  }
 }
}

本文地址:http://com.8s8s.com/it/it45287.htm