(C#)基于值范围的网格列条件格式

时间:2010-08-18 17:01:54

标签: c# math devexpress

我找到了一个很棒的c#示例,根据值的大小来对不同颜色的橙色单元进行着色: http://demos.devexpress.com/ASPxTreeListDemos/Appearance/ConditionalFormatting.aspx

问题在于它希望数字非常大才能发挥作用。有没有办法使用数学公式,我可以指定最大和最小的数字(或所有数字,如果需要),并让它计算橙色的阴影。

以下是上述链接中的具体代码:

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);
 }

我假设数量乘以系数可以以某种方式计算。有什么想法吗?

2 个答案:

答案 0 :(得分:0)

尝试将此行decimal coeff = value / 1000 - 22;更改为decimal coeff = value / 100 - 22;

答案 1 :(得分:0)

相关问题