Skip to main content

ColumnView.FormatRules Property

Provides access to a collection of conditional format rules, which allow you to change the appearance of individual cells or rows based on specific conditions.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v24.1.dll

NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation


[XtraSerializableProperty(XtraSerializationVisibility.Collection, true, false, true, 1000, XtraSerializationFlags.DefaultValue)]
public virtual GridFormatRuleCollection FormatRules { get; }

Property Value

Type Description

A collection of conditional format rules.


The conditional formatting feature allows you to highlight critical information, identifying trends and exceptions, and comparing data.

To apply style format rules to a grid control’s View, use the FormatRules collection. Each rule in this collection is specified by the GridFormatRule object. It identifies a column that provides values for the current rule (GridFormatRule.Column), the rule type (FormatRuleBase.Rule) and other options.

The collection of format rules can be customized at design time and in code. To customize this collection at design time, you can use the Style Format Rules Page (in the Grid Designer), or the Format Rule Collection Editor invoked by clicking the ellipsis button for the FormatRules property (in the Properties window).

GridDesignerFormatRulesPageExampleRules GridFormatRuleCollectionEditorViaPropertiesGrid

If the GridOptionsMenu.ShowConditionalFormattingItem property is enabled, an end-user can customize the format rules collection at runtime using the column’s context menu.

See the Appearance and Conditional Formatting document to learn more.


This example binds a GridControl to a collection of custom Record objects and demonstrates the following features:

  • Assigning an inplace editor (combo box) to a column

  • Specifying a column’s display name and data format by applying DataAnnotation attributes to Record class properties

  • Two ways of changing cell values - at the data source and grid level.

  • Highlighting cell values that meet a condition

Example - RuntimeBinding - Result

View Example

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GridBoundToRuntimeCreatedData {
    public partial class Form1 : Form {
        public Form1() {

        private void Form1_Load(object sender, EventArgs e) {
            gridControl1.DataSource = DataHelper.GetData(10);
            // The grid automatically creates columns for the public fields found in the data source. 
            // Calling the gridView1.PopulateColumns method is not required unless the gridView1.OptionsBehavior.AutoPopulateColumns is disabled

            // Create a ComboBox editor that shows available companies in the Company column
            RepositoryItemComboBox riComboBox = new RepositoryItemComboBox();
            gridView1.Columns["CompanyName"].ColumnEdit = riComboBox;

            // Specify a different null value text presentation for the Image column
            gridView1.Columns["Image"].RealColumnEdit.NullText = "[load image]";

            //Highlight the RequiredDate cells that match a certain condition.
            GridFormatRule gridFormatRule = new GridFormatRule();
            FormatConditionRuleValue formatConditionRuleValue = new FormatConditionRuleValue();
            gridFormatRule.Column = gridView1.Columns["RequiredDate"];
            formatConditionRuleValue.PredefinedName = "Red Bold Text";
            formatConditionRuleValue.Condition = FormatCondition.Greater;
            formatConditionRuleValue.Value1 = DateTime.Today;
            gridFormatRule.Rule = formatConditionRuleValue;
            gridFormatRule.ApplyToRow = false;


        private void btnClearPayment_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
            //Change a cell value at the data source level to see the INotifyPropertyChanged interface in action.
            Record rec = gridView1.GetFocusedRow() as Record;
            if (rec == null) return;
            rec.Value = 0;

        private void btnSetPayment_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
            //Change a cell value at the grid level
            gridView1.SetFocusedRowCellValue("Value", 999);

    public class Record : INotifyPropertyChanged {
        public Record() {
        int id;
        public int ID {
            get { return id; }
            set {
                if (id != value) {
                    id = value;

        string text;
        public string CompanyName {
            get { return text; }
            set {
                if (text != value) {
                    if (string.IsNullOrEmpty(value))
                        throw new Exception();
                    text = value;
        Nullable<decimal> val;
        public Nullable<decimal> Value {
            get { return val; }
            set {
                if (val != value) {
                    val = value;
        DateTime dt;
        [DisplayFormat(DataFormatString = "d")]
        public DateTime RequiredDate {
            get { return dt; }
            set {
                if (dt != value) {
                    dt = value;
        bool state;
        public bool Processed {
            get { return state; }
            set {
                if (state != value) {
                    state = value;
        Image image;
        public Image Image {
            get { return image; }
            set {
                if (image != value) {
                    image = value;
        public override string ToString() {
            return string.Format("ID = {0}, Text = {1}", ID, CompanyName);

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged([CallerMemberName] string propertyName = "") {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

    public class DataHelper {

        public static string[] companies = new string[] { "Hanari Carnes", "Que Delícia", "Romero y tomillo", "Mère Paillarde",
            "Comércio Mineiro", "Reggiani Caseifici", "Maison Dewey" };

        public static Image[] images = new Image[] {

        public static BindingList<Record> GetData(int count) {
            BindingList<Record> records = new BindingList<Record>();
            Random rnd = new Random();
            for (int i = 0; i < count; i++) {
                int n = rnd.Next(10);
                records.Add(new Record() {
                    ID = i + 100,
                    CompanyName = companies[i % companies.Length],
                    RequiredDate = DateTime.Today.AddDays(n - 5),
                    Value = i % 2 == 0 ? (i + 1) * 123 : i * 231,
                    Processed = i % 2 == 0,
                    Image = images[i % images.Length],
            return records;
See Also