Skip to main content

TreeListView.CellValueChanging Event

Occurs 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.v23.2.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public event TreeListCellValueChangedEventHandler CellValueChanging

Event Data

The CellValueChanging event's data class is TreeListCellValueChangedEventArgs. The following properties provide information specific to this event:

Property Description
Cell Gets a processed cell. Inherited from TreeListCellValueEventArgs.
Column Gets a column that contains the edited cell. Inherited from TreeListCellValueEventArgs.
Handled Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.
Node Gets the processed node. Inherited from TreeListNodeEventArgs.
OldValue Gets the cell’s previous value.
OriginalSource Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEvent Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
Row Gets the processed row. Inherited from TreeListNodeEventArgs.
Source Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.
Value Gets or sets the processed cell’s value. Inherited from TreeListCellValueEventArgs.

The event data class exposes the following methods:

Method Description
InvokeEventHandler(Delegate, Object) When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.
OnSetSource(Object) When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.

Remarks

Handle this event to instantly respond to user actions within an in-place editor or Edit Form editor. If you want to maintain a clean MVVM pattern and process cell value edits in a View Model, create a command and bind it to the CellValueChangingCommand property.

The Node and Column properties identify a cell whose value is changing. The TreeListCellValueEventArgs.Value property returns a new cell value.

The CellValueChanging event does not occur when you change cell values 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 TreeListCellValueChangedEventArgs to TreeListCellValueChangedInEditFormEventArgs.

void OnEditFormCellValueChanging(object sender, TreeListCellValueChangedEventArgs e) {
    TreeListCellValueChangedInEditFormEventArgs editFormArgs = e as TreeListCellValueChangedInEditFormEventArgs;
    // ...
}

The TreeListCellValueChangedInEditFormEventArgs 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 row, 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.

void OnEditFormCellValueChanging(object sender, TreeListCellValueChangedEventArgs e) {  
    // ...

    if(e.Cell.Property == nameof(DataItem.CanEdit)) {
        var priceData = editFormArgs.CellEditors.FirstOrDefault(x => x.FieldName == nameof(DataItem.Price));
        priceData.ReadOnly = !bool.Parse(e.Cell.Value.ToString());
        return;
    }

    if(e.Cell.Property == 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)e.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