如何启用DevExpress网格条件格式?

时间:2020-10-27 13:15:52

标签: devexpress devexpress-windows-ui devexpress-gridcontrol

我有一个.net,C#Windows Form项目。我正在使用DevExpress 19.1。在我的GridControl上,当列小于0时,我有条件格式。当值小于0时,我希望该单元格突出显示为红色,但它不起作用。我尝试过使用表达式,条件和值,仅适用于一列,适用于整个角色,但我始终无法突出显示。有人可以告诉我我在做什么错吗?

以下是该规则在代码中的显示方式:

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

这是我在设计器中设置规则的方式:

enter image description here

在输出中,您可以看到该值小于0并且背景颜色保持不变:

enter image description here

2 个答案:

答案 0 :(得分:1)

我看到网格中只有一行。网格总是有焦点的行。聚焦行外观的优先级高于条件外观。禁用GridView.OptionsSelection.EnableAppearanceFocusedCellGridView.OptionsSelection.EnableAppearanceFocusedRow属性以删除焦点所在的行外观。

this.gvProducts.OptionsSelection.EnableAppearanceFocusedCell = false;
this.gvProducts.OptionsSelection.EnableAppearanceFocusedRow = false;

或者,将FormatConditionRuleValue.Appearance.Options.HighPriority属性设置为true

formatConditionRuleValue3.Appearance.Options.HighPriority = true;

Appearance settings

答案 1 :(得分:1)

相关问题