views:

33

answers:

2

I found a great c# example that colors cells in different shades of orange based on the how large or small the value is: http://demos.devexpress.com/ASPxTreeListDemos/Appearance/ConditionalFormatting.aspx

The problem is that it expects the numbers to be very large for it to work. Is there a way using a math formula that I could specify the largest and smallest number (or all numbers if needed) and have it calculate the shade of orange that way.

Here is the specific code from the link above:

protected void treeList_HtmlDataCellPrepared(object sender, TreeListHtmlDataCellEventArgs e) {
     if(e.Column.Name == "budget") {
         decimal value = (decimal)e.CellValue;
         e.Cell.BackColor = GetBudgetColor(value);
         if(value > 1000000M)
             e.Cell.Font.Bold = true
     }
 }

 Color GetBudgetColor(decimal value) {
     decimal coeff = value / 1000 - 22;
     int a = (int)(0.02165M * coeff);
     int b = (int)(0.09066M * coeff);
     return Color.FromArgb(255, 235 - a, 177 - b);
 }

I'm assuming that the number multiplied times the coeff could be calculated somehow. Any ideas?

A: 

try changing this line decimal coeff = value / 1000 - 22; to decimal coeff = value / 100 - 22;

BioBuckyBall
I don't see how that would handle any range of numbers. I did find an answer on the MSDN blog, although it uses a different method. Thanks though for the response!
lpage