突出显示前 20% 列值

Goto Appearance and Conditional Formatting 外观和条件格式

突出显示前 20% 列值

此示例说明了如何在设计时使用网格设计器和在代码中将 top/bottom 格式应用于 GridControl 中的 Sales vs Target 列。

top/bottom 格式允许您查找最高或最低的单元格值。在本教程中,突出显示了 Sales vs Target 列中的前 20% 值(截止值为 20)。

在这里插入图片描述
要在设计时创建新的格式规则,请从网格设计器中调用格式规则集合编辑器。还可以通过单击 ColumnView.FormatRules 属性的省略号按钮,从 Properties 网格中访问它。

调用 Grid Designer 并切换到 Style Format Rules 页面(在 Appearance 类别中)。

在这里插入图片描述

单击 Add 按钮 GridDesignerAddButton 以创建新的格式规则(GridControl 中的格式规则由 GridFormatRule 对象封装)。

选择 Format only top ranked 或 bottom ranked values 规则类型。格式规则的 FormatRuleBase.Rule 属性将设置为新的 FormatConditionRuleTopBottom 对象。

在这里插入图片描述

将 GridFormatRule.Column 属性设置为 Sales vs Target 列。此列提供要根据格式设置规则进行测试的值。

在这里插入图片描述
默认情况下,该格式将应用于同一列。但是,您可以通过设置 GridFormatRule.ColumnApplyTo 属性将此格式应用于其他列。此外,您还可以通过将 GridFormatRule.ApplyToRow 属性设置为 true 来将格式应用于整行。

使用 FormatConditionRuleAppearanceBase.PredefinedName 属性选择一种预定义的样式格式。您可以在 Properties 选项卡或 Rule 选项卡。的 Rule 选项卡还允许您查看所选样式的预览。在此示例中,选择了 Green Fill with Green Text 样式格式。

在这里插入图片描述
您还可以使用 FormatConditionRuleAppearanceBase.Appearance 属性提供自定义样式格式。

使用 FormatConditionRuleTopBottom.Rank 属性将截止值设置为 20。

选择 Percent rank 类型(FormatConditionRuleTopBottom.RankType 属性)以将截止值视为百分比。

将 FormatConditionRuleTopBottom.TopBottom 属性设置为 Top 以突出显示最高列值。

在这里插入图片描述

运行应用程序。下图说明了结果。Sales vs Target 列中的前 20% 值使用浅绿色背景和深绿色前景色突出显示。

在这里插入图片描述

以下代码等效于上面显示的设计时操作。

/*
 * 突出显示前 20% 列值
 */
GridFormatRule gridFormatRule5 = new GridFormatRule();
FormatConditionRuleTopBottom formatConditionRuleTopBottom = new FormatConditionRuleTopBottom();
gridFormatRule5.Column = gridView1.Columns["charge_total"];
formatConditionRuleTopBottom.PredefinedName = "Green Fill, Green Text";
formatConditionRuleTopBottom.Rank = 20;
formatConditionRuleTopBottom.RankType = FormatConditionValueType.Percent;
formatConditionRuleTopBottom.TopBottom = FormatConditionTopBottomType.Top;
gridFormatRule5.Rule = formatConditionRuleTopBottom;
gridView1.FormatRules.Add(gridFormatRule5);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值