Format Condition Types

  • 4 minutes to read

The ASPxGridView control provides the following types of format conditions.

Color Scale Format Condition

The GridViewFormatConditionColorScale format condition allows you to color grid cells using a two-color or three-color scale. Cells are shaded with gradations of two or three colors that correspond to minimum, middle, and maximum thresholds.

The conditional formatting is determined for the column specified by the GridFormatConditionBase.FieldName property. By default, formatting is applied to the same column. However, you can specify the column to which formatting will be applied using the GridViewFormatConditionColorScale.ShowInColumn property. The format (color scale) can be specified by the GridFormatConditionColorScale.Format property, which provides a number of predefined formats.

Custom Format

If the GridFormatConditionColorScale.Format property is set to Custom, you can specify custom colors for a scale by using the GridFormatConditionColorScale.MinimumColor, GridFormatConditionColorScale.MiddleColor (optional), and GridFormatConditionColorScale.MaximumColor properties.

Example

FormatConditionType_ColorScale

The code snippets below demonstrate how to create and customize a color scale format condition at design time and at runtime.

GridViewFormatConditionColorScale Rule = new GridViewFormatConditionColorScale();
Rule.FieldName = "Quantity";
Rule.Format = GridConditionColorScaleFormat.BlueWhiteRed;
Grid.FormatConditions.Add(Rule);

Highlight Format Condition

The GridViewFormatConditionHighlight format condition allows you to highlight cell values based on a custom expression.

The conditional formatting is determined for the column specified by the GridFormatConditionBase.FieldName property. By default, formatting is applied to the same column. However, you can specify the column to which formatting will be applied using the GridViewFormatConditionHighlight.ShowInColumn property. The style format, which can be specified by the GridFormatConditionExpressionBase.Format property, is applied to a cell (or row, provided the GridViewFormatConditionHighlight.ApplyToRow property is set to true) whose value meets the condition specified by the GridFormatConditionHighlight.Rule property. When this property is set to Expression, use the GridFormatConditionHighlight.Expression property to specify a custom rule expression.

Custom Format

If the GridFormatConditionExpressionBase.Format property is set to Custom, the formatting style can be specified by the GridViewFormatConditionHighlight.CellStyle or GridViewFormatConditionHighlight.RowStyle property, based on the GridViewFormatConditionHighlight.ApplyToRow property value.

FormatConditionType_Highlight

The code snippets below demonstrate how to create and customize a highlight format condition at design time and at runtime.

GridViewFormatConditionHighlight Rule = new GridViewFormatConditionHighlight();
Rule.FieldName = "Discount";
Rule.Expression = "[Discount] > 0";
Rule.Format = GridConditionHighlightFormat.GreenFillWithDarkGreenText;
Grid.FormatConditions.Add(Rule);

Icon Set Format Condition

The GridViewFormatConditionIconSet format condition allows you to provide grid cells with predefined icons.

The conditional formatting is determined for the column specified by the GridFormatConditionBase.FieldName property. By default, formatting is applied to the same column. However, you can specify the column to which formatting will be applied using the GridViewFormatConditionIconSet.ShowInColumn property. The format (icon set) can be specified by the GridFormatConditionIconSet.Format property.

FormatConditionType_IconSet

The code snippets below demonstrate how to create and customize an icon set format condition at design time and at runtime.

GridViewFormatConditionIconSet Rule = new GridViewFormatConditionIconSet();
Rule.FieldName = "Total";
Rule.Format = GridConditionIconSetFormat.Ratings5;
Grid.FormatConditions.Add(Rule);

Top/Bottom Format Condition

The GridViewFormatConditionTopBottom format condition allows you to highlight top or bottom cell values.

Conditional formatting is determined for the column specified by the GridFormatConditionBase.FieldName property. By default, formatting is applied to the same column. However, you can specify the column to which formatting will be applied using the GridViewFormatConditionTopBottom.ShowInColumn property. The style format, which can be specified by the GridFormatConditionExpressionBase.Format property, is applied to a cell (or row, provided the GridViewFormatConditionTopBottom.ApplyToRow property is set to true) whose value meets the condition specified by the GridFormatConditionTopBottom.Rule property. When the GridFormatConditionTopBottom.Rule property is set to BottomItems, BottomPercent, TopItems, or TopPercent values, use the GridFormatConditionTopBottom.Threshold property to specify additional condition information, i.e., the number of items or the percentage. The AboveAverage and BelowAverage values do not require additional parameters.

Custom Format

If the GridFormatConditionExpressionBase.Format property is set to Custom, the formatting style can be specified by the GridViewFormatConditionTopBottom.CellStyle or GridViewFormatConditionTopBottom.RowStyle property (based on the GridViewFormatConditionTopBottom.ApplyToRow property value).

FormatConditionType_TopBottom

The code snippets below demonstrate how to create and customize a top/bottom scale format condition at design time and at runtime.

GridViewFormatConditionTopBottom Rule = new GridViewFormatConditionTopBottom();
Rule.FieldName = "UnitPrice";
Rule.Rule = GridTopBottomRule.AboveAverage;
Rule.Format = GridConditionHighlightFormat.RedText;
Grid.FormatConditions.Add(Rule);