CSDN博客

img haibodotnet

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

发表于2003/11/19 12:18:00  4075人阅读

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

相关文章推荐

img
取 消
img