Back to Devexpress

FormatConditionRuleTopBottom Class

windowsforms-devexpress-dot-xtraeditors-96ee0197.md

latest8.0 KB
Original Source

FormatConditionRuleTopBottom Class

Applies a format if a value is in the range of the highest or lowest column values.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
public class FormatConditionRuleTopBottom :
    FormatConditionRuleAppearanceBase,
    IConditionalFilterItemProvider,
    IFormatConditionRuleTopBottom,
    IFormatConditionRuleBase
vb
Public Class FormatConditionRuleTopBottom
    Inherits FormatConditionRuleAppearanceBase
    Implements IConditionalFilterItemProvider,
               IFormatConditionRuleTopBottom,
               IFormatConditionRuleBase

Remarks

You can find the highest or lowest column values based on a cutoff value. This value is specified by the FormatConditionRuleTopBottom.Rank property. Its type (numeric or percentage) is specified by the FormatConditionRuleTopBottom.RankType property.

The FormatConditionRuleTopBottom.TopBottom property specifies the type of the target range (above or below the cutoff value).

You can use the FormatConditionRuleAppearanceBase.PredefinedName property to apply one of the predefined style formats (Italic Text, Red Bold Text, Green Fill, Yellow Text with Yellow Fill, etc.), or use the FormatConditionRuleAppearanceBase.Appearance property to provide a custom appearance.

The images below demonstrate examples of applying a FormatConditionRuleTopBottom format.

See the following documents to learn more.

Example

This example illustrates how to apply a top/bottom format to the Sales vs Target column in a GridControl at design time using the Grid Designer and in code.

The top/bottom format allows you to find highest or lowest cell values. In this tutorial, the top 20% values in the Sales vs Target column are highlighted (the cutoff value is 20 ).

To create a new formatting rule at design time, invoke the Format Rule Collection Editor from the Grid Designer. It can also be accessed from the Properties grid by clicking the ellipsis button for the ColumnView.FormatRules property.

  1. Invoke the Grid Designer and switch to the Style Format Rules page (in the Appearance category).

  2. Click the Add button to create a new format rule (format rules in a GridControl are encapsulated by GridFormatRule objects).

  3. Select the Format only top or bottom ranked values rule type. The format rule’s FormatRuleBase.Rule property will be set to a new FormatConditionRuleTopBottom object.

  4. Set the GridFormatRule.Column property to the Sales vs Target column. This column provides values to test against the formatting rule.

  5. Choose one of the predefined style formats using the FormatConditionRuleAppearanceBase.PredefinedName property. You can do this in the Properties tab or the Rule tab. The Rule tab additionally allows you to see a preview of the selected style. In this example, the Green Fill with Green Text style format is selected.

  6. Set the cutoff value to 20 using the FormatConditionRuleTopBottom.Rank property.

  7. Choose the Percent rank type (the FormatConditionRuleTopBottom.RankType property) to regard the cutoff value as a percentage.

  8. Set the FormatConditionRuleTopBottom.TopBottom property to Top to highlight the highest column values.

  9. Run the application. The image below illustrates the result. The top 20% values in the Sales vs Target column are highlighted using a light green background and dark green foreground color.

The following code is equivalent to the design-time actions shown above.

csharp
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;

GridFormatRule gridFormatRule = new GridFormatRule();
FormatConditionRuleTopBottom formatConditionRuleTopBottom = new FormatConditionRuleTopBottom();
gridFormatRule.Column = colSalesVsTarget;
formatConditionRuleTopBottom.PredefinedName = "Green Fill, Green Text";
formatConditionRuleTopBottom.Rank = 20;
formatConditionRuleTopBottom.RankType = FormatConditionValueType.Percent;
formatConditionRuleTopBottom.TopBottom = FormatConditionTopBottomType.Top;
gridFormatRule.Rule = formatConditionRuleTopBottom;
gridView1.FormatRules.Add(gridFormatRule);
vb
Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid

Dim gridFormatRule As New GridFormatRule()
Dim formatConditionRuleTopBottom As New FormatConditionRuleTopBottom()
gridFormatRule.Column = colSalesVsTarget
formatConditionRuleTopBottom.PredefinedName = "Green Fill, Green Text"
formatConditionRuleTopBottom.Rank = 20
formatConditionRuleTopBottom.RankType = FormatConditionValueType.Percent
formatConditionRuleTopBottom.TopBottom = FormatConditionTopBottomType.Top
gridFormatRule.Rule = formatConditionRuleTopBottom
gridView1.FormatRules.Add(gridFormatRule)

Inheritance

Object FormatConditionRuleBase FormatConditionRuleAppearanceBase FormatConditionRuleTopBottom

See Also

FormatConditionRuleTopBottom Members

Appearance and Conditional Formatting

Conditional Formatting

Conditional Formatting

DevExpress.XtraEditors Namespace