Skip to main content

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.v24.2.dll

Declaration

public class FormatConditionRuleTopBottom :
    FormatConditionRuleAppearanceBase,
    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.

FormatUnitPriceTopValue FormatTopBottomMarketShare

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

GridFormatRuleTopBottomExampleResult

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

    GridDesignerAppearanceCategoryFormatRulesPage

  2. Click the Add button GridDesignerAddButton 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.

    CreateNewTopBottomRuleViaGridDesigner

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

    SelectColumnForTopBottomFormatRule

    By default, the format is applied to the same column. However, you can apply this format to another column by setting the GridFormatRule.ColumnApplyTo property. In addition, you can apply the format to the entire row by setting the GridFormatRule.ApplyToRow property to true.

  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.

    FormatRuleTopBottomPredefinedName

    You can also provide a custom style format using the FormatConditionRuleAppearanceBase.Appearance property.

  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.

    FormatRuleTopBottomExampleSettings

  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.

    GridFormatRuleTopBottomExampleResult

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

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

Inheritance

See Also