0

I'm trying to format the string in the expression for the Style Format Condition to paint the background color of the cell with some color if the condition it's true. My condition it's only to compare if the substraction of two values is equal to another value, I execute the comparison like this because the values are double and it's necessary to avoid precision errors, where EPSILON is 0.001:

if (Math.Abs(rvalue - tara - value) > EPSILON)
{
   // do something
}

I'm trying this code , but doesn't work, please if someone can do this, please help me. Thanks

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

1 回答 1

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; }
}
于 2013-10-29T09:25:33.060 回答