Click here to Skip to main content
15,569,547 members
Please Sign up or sign in to vote.
3.00/5 (4 votes)
See more:
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

C#
If {dtStudents.Mark} > 1 Then
    crGreen 


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

My Question is How we do that programmatically ?
Posted
Updated 9-Jun-12 14:16pm
v2
Comments
Sandeep Mewara 9-Jun-12 14:52pm    
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.
thatraja 10-Jun-12 4:58am    
Why downvotes? It's a tricky question, Have 5 from me.

1 solution

You could use parameter fields[^].

In report, create a parameter field prmMark.

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


Now, from from your code-behind send the value to parameter field prmMark. Sample code from above link.
C#
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();

}
 
Share this answer
 
Comments
masalahi 10-Jun-12 17:05pm    
you gust send the value to parameter field
but i want to send all the formula
is that possible?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900