Using QES - Scripting example to do more complex report formatting

In this example the customer wanted to force two decimal places on the results on the COA average report when the field was a number and when it is text show the text.   This could not be completed with conditional formatting or any other method so .net scripting was required to solve this issue:

  1. Click on the field that you want to put the script on.
  2. In the property grid scroll to "Scripts"
  3. Click the little arrow the the left of scripts to expand the different places the script can run from
  4. Click on "Before Print"
  5. Click the down arrow and say "New"
  6. Write the required script to format the data as required.

private void xrLabel_NumResultsAvg_DecimalSet_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
decimal number;

if (System.Decimal.TryParse(xrLabel_NumResultsAvg_DecimalSet.Text, out number))
{
//then it's a number
//format it to 2 decimal places
xrLabel_NumResultsAvg_DecimalSet.Text = String.Format("{0:0.00}", xrLabel_NumResultsAvg_DecimalSet.Text); }
else
{
//it's text
//label6.Text = "Number";

}

}