我正在尝试格式化样式格式条件的表达式中的字符串,如果条件为真,则使用某种颜色绘制单元格的背景颜色。我的条件是只比较两个值的减法是否等于另一个值,我执行这样的比较,因为值是双倍的,有必要避免精度误差,其中EPSILON为0.001:
if (Math.Abs(rvalue - tara - value) > EPSILON)
{
// do something
}
我正在尝试使用此代码但不起作用,如果有人可以这样做,请帮助我。感谢
var condExpression = new StyleFormatCondition(FormatConditionEnum.Expression);
condExpression.Column = gv_MateriaPrima.Columns[3];
condExpression.Appearance.BackColor = Color.OrangeRed;
condExpression.Expression = String.Format("Abs([FieldName] - {0} - {1}) > {2}",
value1, value2, EPSILON);
答案 0 :(得分:0)
您是否已将格式条件添加到GridView.FormatConditions集合中? 以下是适用于我的代码段(请检查与您的代码的差异):
// just sample data
gridControl1.DataSource = new List<DataObj> {
new DataObj() { RValue = 0.2 },
new DataObj() { RValue = 0.21 }, // !!! Orange
new DataObj() { RValue = 0.201 }, // !!! Orange
new DataObj() { RValue = 0.2001 },
new DataObj() { RValue = 0.20001 },
};
gridView1.PopulateColumns();
//...
var condExpression = new StyleFormatCondition(FormatConditionEnum.Expression);
condExpression.Column = gridView1.Columns["RValue"];
condExpression.Appearance.BackColor = Color.OrangeRed;
condExpression.Appearance.Options.UseBackColor = true;
condExpression.Expression = String.Format("Abs([RValue] - {0} - {1}) > {2}", 0.1, 0.1, EPSILON);
gridView1.FormatConditions.Add(condExpression);
//...
class DataObj {
public double RValue { get; set; }
}