Skip to main content
All docs
V24.1

TreeListView.CellValueChangingCommand Property

Gets or sets a command executed when a user edits a cell value (for example, types or deletes a character, chooses a value from the drop-down list).

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v24.1.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public ICommand<CellValueChangedArgs> CellValueChangingCommand { get; set; }

Property Value

Type Description
ICommand<CellValueChangedArgs>

A command executed when a user edits a cell value (for example, types or deletes a character, chooses a value from the drop-down list).

Remarks

Bind a command to the CellValueChangingCommand property to maintain a clean MVVM pattern. The command works like a CellValueChanging event handler and allows you to process cell value edits in a View Model.

The GridControl does not call a command bound to CellValueChangingCommand when you change a cell value in code.

Refer to the following topic for more information: Obtain and Set Cell Values.

Edit Form

If you process data edit operations in the Edit Form, you need to cast CellValueChangedArgs to CellValueChangedInEditFormArgs.

[Command]
public void SynchronizeValues(CellValueChangedArgs args) {
    var editFormArgs = (CellValueChangedInEditFormArgs)args;
    // ...
}

The CellValueChangedInEditFormArgs class contains the CellEditors property that returns an array of CellEditorData objects. Each object allows you to specify editor’s settings. When users edit a node, you may want to initialize values or make certain editors read-only. To do that, specify the corresponding CellEditorData.Value property or set the CellEditorData.ReadOnly property to true.

The following code sample disables the Price editor depending on the CanEdit value and assigns the result of Price and Amount multiplication to the PositionValue editor.

[Command]
public void SynchronizeValues(CellValueChangedArgs args) {
// ...
    if(args.FieldName == nameof(DataItem.CanEdit)) {
        var priceData = editFormArgs.CellEditors.FirstOrDefault(x => x.FieldName == nameof(DataItem.Price));
        priceData.ReadOnly = !bool.Parse(args.Value.ToString());
        return;
    }

    if(args.FieldName == nameof(DataItem.Price)) {
        var positionValueData = editFormArgs.CellEditors.First(d => d.FieldName == nameof(DataItem.PositionValue));
        var amountData = editFormArgs.CellEditors.First(d => d.FieldName == nameof(DataItem.Amount));

        int price = 0;

        int.TryParse((string)args.Value, out price);
        positionValueData.Value = (int)amountData.Value * price;
    }
}

View Example: Data Grid for WPF - How to Process Related Cells in the Edit Form

See Also