All docs
V21.2
21.2
21.1
20.2
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Disabled Cell Behavior

  • 4 minutes to read

Overview

This Behavior allows you to disable cells in rows that meet a certain condition. Disabled cells are grayed-out according to the skin settings. Users cannot edit disabled cells. For example, you can disable rows that display orders that are older than six months.

image

Supported Controls

How to Attach the Behavior to a Control in the Designer

To attach the Behavior to a control, use the standard approach:

  • Drop the BehaviorManager component from Visual Studio’s Toolbox onto the component tray.
  • Click Edit Behaviors in the component’s smart image tag menu.
  • In the Add drop-down menu, select Disabled Cell Behavior.

image

Options

When the Behavior is attached, use the editor to specify the following options:

  • The Appearance property — appearance settings applied to disabled cells. The default settings depend on the current skin. This property allows you to adjust them. For example, you can change the background color, font style, and so on.
  • The Expression property — a string value that specifies a condition that disabled rows should meet. For example, DateDiffMonth([Sales Date], Today()) > 6 disables rows with orders that are older than six months.

    Click the property’s ellipsis button to invoke the expression editor.

    image

  • The ProcessingCell event — allows you to enable/disable a cell.

    Use the FieldName event arguments to get the processed cell’s field name. The RecordId argument identifies the row/node/record that contains the processed cell. This argument returns the following values depending on the attached control:

    Set the Disabled argument to true to disable the processed cell. The code below disables rows only if the user checked a dedicated option, but never disables cells in the ‘Order ID’ column.

    image

    using DevExpress.Utils.Behaviors.Common;
    
    private void disabledCellEvents1_ProcessingCell(object sender, ProcessCellEventArgs e) {
        bool evaluationResult = e.Disabled;
        evaluationResult = checkEdit1.Checked ? evaluationResult : false;
        e.Disabled = e.FieldName == "OrderID" ? false : evaluationResult;
    }
    // Use the grid view's LayoutChanged method to force the Behavior
    // to recalculate disabled cells.
    private void checkEdit1_CheckedChanged(object sender, EventArgs e) {
        gridView1.LayoutChanged();
    }
    

    Note

    See Code Examples in the XtraGrid demo for more samples.

    You can add an event handler in the editor’s events tab, or use the DisabledCellEvents component in the Properties window.

    image

How to Attach the Behavior to a Control in Code

The example below shows how to attach the Behavior to a control in code, specify its settings, and add event handlers.

using DevExpress.Utils.Behaviors;
using DevExpress.Utils.Behaviors.Common;

BehaviorManager bm = new BehaviorManager(this.components);
bm.Attach<DisabledCellBehavior>(gridView1, behavior => {
    behavior.Properties.Expression = "DateDiffMonth([Sales Date], Today()) > 6";
    behavior.Properties.Appearance.BackColor = System.Drawing.Color.AliceBlue;
    behavior.Properties.Appearance.FontStyleDelta = System.Drawing.FontStyle.Italic;
    behavior.ProcessingCell += (s, e) => { if (!checkEdit1.Checked) e.Disabled = false; };
});

// Use the Detach method to remove the Behavior.
bm.Detach<DisabledCellBehavior>(gridView1);