I have a .net, C# Windows Form project. I'm using DevExpress 19.1. On my GridControl, I have conditional formatting for when a column is less than 0. I want the cell to be highlighted red when the value is less than 0, but it's not working. I've tried using an expression, a condition and value, applying to just a column, applying to the whole role, but I never get the highlighting to work. Can someone tell me what I'm doing wrong?
Here is how the rule looks liked in code:
gridFormatRule3.ApplyToRow = true;
gridFormatRule3.Column = this.colQuantityLeft;
gridFormatRule3.ColumnApplyTo = this.colQuantityLeft;
gridFormatRule3.Name = "Format0";
formatConditionRuleValue3.Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
formatConditionRuleValue3.Appearance.Options.UseBackColor = true;
formatConditionRuleValue3.Condition = DevExpress.XtraEditors.FormatCondition.Less;
formatConditionRuleValue3.Expression = "[QuantityLeft] < 0";
formatConditionRuleValue3.Value1 = 0;
gridFormatRule3.Rule = formatConditionRuleValue3;
this.gvProducts.FormatRules.Add(gridFormatRule3);
Here's how I set the rules in the Designer:
Here's the output where you can see the value is less than 0 and the background color is not changed:
I see that you have only one row in the grid. The grid always has a focused row. The focused row appearance has a higher priority than conditional appearance. Disable the GridView.OptionsSelection.EnableAppearanceFocusedCell and GridView.OptionsSelection.EnableAppearanceFocusedRow properties to remove the focused row appearance.
this.gvProducts.OptionsSelection.EnableAppearanceFocusedCell = false;
this.gvProducts.OptionsSelection.EnableAppearanceFocusedRow = false;
Alternatively, set the FormatConditionRuleValue.Appearance.Options.HighPriority property to true
.
formatConditionRuleValue3.Appearance.Options.HighPriority = true;