Conditional formatting of background color

Stimulsoft Reports.NET discussion
Post Reply
Scottioioio
Posts: 47
Joined: Thu Dec 20, 2012 6:58 pm

Conditional formatting of background color

Post by Scottioioio »

I have a query that returns a status message ("Operating," "Down for maintenance," etc.) as well as the background color to use to display the status message ("000000", "FF0000", etc.).

How do I set the background color based on the data returned by the query? Ideally, I'd be able to do this using the Conditions dialog in the Designer.

I found a post that said to do the following:
Dim backColor As String

backColor = {Field.FieldValue}
Text1.Brush = New StiSolidBrush(ColorTranslator.FromOle(backColor))
But I'm not clear where I put this. I tried double-clicking on the text cell in the table and going to the Summary tab and entering this as a Condition, but I get errors when attempting to run my report.

Thanks
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Conditional formatting of background color

Post by HighAley »

Hello.

You could use this code in the Before Print event of the Text box.

Also if you have a fixed colours then it's better to use the Condition for each colour using expression like next:
YourDataSource.Colour == "00000000"
Thank you.
Scottioioio
Posts: 47
Joined: Thu Dec 20, 2012 6:58 pm

Re: Conditional formatting of background color

Post by Scottioioio »

Aleksey, this approach works well for regular text boxes in the report, but I am working with the text in a cell in a databound table.

For example, if I add a textbox to my report (Text1) I can create a Before Print event with the following code:

Code: Select all

Text1.TextBrush = new StiSolidBrush(Color.Red);
And when I view the report the text is red.

However, if I create a Before Print event handler for the text in a cell in the databound table, and put the same code as above, Text1 is not red.

Long story short, we let the user define certain thresholds for which alerts need to be displayed (e.g., if output is less than 20% then flag as warning 1, if output is less than 40% then warning 2, etc.). We also let users specify the colors for various alerts, so the user could say they want to show warning 1 as red and warning 2 as orange, or whatever.

I have a table that shows the outputs for various pieces of machinery and in one column I want to show the alert (if any) with the appropriate color.

So imagine the user defines the alert levels as I described above and there exists the following data for the machines:

Machine1 - output=50%
Machine2 - output=34%
Machine3 - output=11%

What the report should look like is this:

Machine1 - output = 50% - NO ALERT
Machine2 - output = 34% - Warning 2
Machine3 - output = 11% - Warning 1


If another user defined the alert levels so that at output <= 50% is warning 1 and output <= 75% is warning 2 and warning 1 is purple and warning 2 is green, then their report would look like:

Machine1 - output = 50% - Warning 2
Machine2 - output = 34% - Warning 1
Machine3 - output = 11% - Warning 1

Does that make sense? How can I do this with Stimulasoft?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Conditional formatting of background color

Post by HighAley »

Hello.

You could do it using Conditions and Styles.
Please, look at the attached report template.
Report.mrt
(10.51 KiB) Downloaded 851 times
data.xml
(383 Bytes) Downloaded 474 times
Thank you.
Scottioioio
Posts: 47
Joined: Thu Dec 20, 2012 6:58 pm

Re: Conditional formatting of background color

Post by Scottioioio »

Aleksey, thank you for your response, but I don't see how you are setting the color dynamically. In other words, in addition to being able to specify the bounds at which different warning messages are displayed, the user is also able to specify the color.

I don't see how I can set the brush color of a style dynamically based on the value of a variable or from a data source, or how to configure a condition such that the brush color can be set dynamically based on the value of a variable or from a data source.

Is this type of functionality possible?

Thanks
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Conditional formatting of background color

Post by HighAley »

Hello.

I have added 2 string variables and a code in the Begin Render event of the report.
Report.mrt
(10.93 KiB) Downloaded 864 times
Thank you.
Scottioioio
Posts: 47
Joined: Thu Dec 20, 2012 6:58 pm

Re: Conditional formatting of background color

Post by Scottioioio »

Aleksey, thank you for the sample report. I was able to use the concepts illustrated in the sample to get it working.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Conditional formatting of background color

Post by HighAley »

Hello.

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

Thank you.
Post Reply