Formatting StiText using dynamic data

Stimulsoft Reports.NET discussion
Post Reply
Christopher Lloyd
Posts: 23
Joined: Wed Apr 13, 2011 7:37 am
Location: UK

Formatting StiText using dynamic data

Post 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
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Formatting StiText using dynamic data

Post 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.
Christopher Lloyd
Posts: 23
Joined: Wed Apr 13, 2011 7:37 am
Location: UK

Formatting StiText using dynamic data

Post by Christopher Lloyd »

Thank you Aleksey,

That has worked like a dream.

Chris L
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Formatting StiText using dynamic data

Post by Alex K. »

Hello,

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

Thank you.
Post Reply