Page 1 of 1

Formatting StiText using dynamic data

Posted: Wed Apr 13, 2011 7:50 am
by Christopher Lloyd
Hi,

I've written a wrapper in C# that loads a template report and then dynamically adds the data bands into the report.

My problem is that I am having trouble changing the brush colour to red for negative numbers. After I compile my report I add the following line to listen for the event:

report.CompiledReport.GetComponents()["Total"].BeforePrint += new EventHandler(this.DataDataSource1_Column_Conditions);

And then I process the event with the following code:

if ((((decimal)(StiReport.ChangeType(report.DataSources[0][sender.ToString()], typeof(decimal), true))) <= 0m))
{
((Stimulsoft.Report.Components.IStiTextBrush)(sender)).TextBrush = new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.Red);
((Stimulsoft.Report.Components.IStiBrush)(sender)).Brush = new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.Transparent);
((Stimulsoft.Report.Components.IStiFont)(sender)).Font = new System.Drawing.Font("Arial", 8F);
((Stimulsoft.Report.Components.StiComponent)(sender)).Enabled = true;
return;
}


The problem with this code is that it is only ever looking at the first row of data.

Any ideas or help on where am I going wrong?

Chris L

Formatting StiText using dynamic data

Posted: Thu Apr 14, 2011 2:12 am
by Alex K.
Hello,

As a way, you can use the following code after load report:

Code: Select all

StiText textComp = report.GetComponents()["Total"] as StiText;
StiCondition cond = new StiCondition("DataSourceName.ColumnName <= 0", Color.Red, Color.Transparent, new System.Drawing.Font("Arial", 8F), true);
textComp.Conditions.Add(cond);
Thank you.

Formatting StiText using dynamic data

Posted: Thu Apr 14, 2011 3:43 am
by Christopher Lloyd
Thank you Aleksey,

That has worked like a dream.

Chris L

Formatting StiText using dynamic data

Posted: Thu Apr 14, 2011 6:08 am
by Alex K.
Hello,

We are always glad to help you!
Let us know if you need any additional help.

Thank you.