如何以编程方式更改Crystal Report字段的格式公式? [英] How to change Format Formula for field of Crystal Report programmatically ?

查看:75
本文介绍了如何以编程方式更改Crystal Report字段的格式公式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们想要更改Crystal Report的任何字段的颜色时,我们将更改该字段的格式公式
然后在Field>< FormatObject>> Font>> Color上执行>>"鼠标右键,然后按公式按钮
在编辑器中,我们将代码

When we want to chang the color of any field of Crystal Report we change the formatting formula of the field
and we do that >>right mouse button on Field>>FormatObject>>Font>>Color and press the formula button
in the Editor we put the code

If {dtStudents.Mark} > 1 Then
    crGreen 



当值大于等于时,字段的颜色将更改. 1

我的问题是我们如何以编程方式进行操作?



and the color of the field will change when the value is > 1

My Question is How we do that programmatically ?

推荐答案

您可以使用
You could use parameter fields[^].

In report, create a parameter field prmMark.

Change the formula something like as below
If {dtStudents.Mark} > @prmMark Then
    crGreen



现在,从您的代码后面,将该值发送到参数字段prmMark.以上链接的示例代码.



Now, from from your code-behind send the value to parameter field prmMark. Sample code from above link.

private void button1_Click(object sender, EventArgs e)
{
    ReportDocument cryRpt = new ReportDocument();
    cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");

    ParameterFieldDefinitions crParameterFieldDefinitions ;
    ParameterFieldDefinition crParameterFieldDefinition ;
    ParameterValues crParameterValues = new ParameterValues();
    ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

    crParameterDiscreteValue.Value = Convert.ToInt32(textBox1.Text);
    crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
    crParameterFieldDefinition = crParameterFieldDefinitions["prmMark"];
    crParameterValues = crParameterFieldDefinition.CurrentValues;

    crParameterValues.Clear();
    crParameterValues.Add(crParameterDiscreteValue);
    crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

    crystalReportViewer1.ReportSource = cryRpt;
    crystalReportViewer1.Refresh();

}


这篇关于如何以编程方式更改Crystal Report字段的格式公式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆