开发者

(C#) Conditional Formatting on Grid Column Based on Value Range

开发者 https://www.devze.com 2023-01-12 07:15 出处:网络
I found a great c# example that colors cells in different shades of orange based on the how large or small the value is:

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 numbe开发者_JS百科r multiplied times the coeff could be calculated somehow. Any ideas?


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


http://blogs.msdn.com/b/bobmeyers/archive/2009/07/31/add-excel-like-color-scale-conditional-formatting-to-your-reports.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消