Back to Devexpress

TreeListView.CellEditorValueChangingCommand Property

wpf-devexpress-dot-xpf-dot-grid-dot-treelistview-22d24e8d.md

latest4.0 KB
Original Source

TreeListView.CellEditorValueChangingCommand Property

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

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public ICommand<CellEditorValueChangingArgs> CellEditorValueChangingCommand { get; set; }
vb
Public Property CellEditorValueChangingCommand As ICommand(Of CellEditorValueChangingArgs)

Property Value

TypeDescription
ICommand<CellEditorValueChangingArgs>

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, etc.).

|

Remarks

The TreeListControl does not execute a command bound to CellValueChangingCommand when you change a cell editor value in code.

To restore the previous cell editor value (and prevent the CellValueChanging event from occurring), set the Cancel property to true.

Example

The following example prompts a user before changing a cell value (if the action is canceled, the cell value remains unchanged):

xaml
<ThemedWindow ...
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">

    <dxmvvm:Interaction.Behaviors>
        <dx:DXMessageBoxService/>
    </dxmvvm:Interaction.Behaviors>

    <Grid>
        <dxg:TreeListControl ItemsSource="{Binding DataItems}">
            <dxg:TreeListControl.Columns>
                <dxg:TreeListColumn FieldName="Name"/>
                <dxg:TreeListColumn FieldName="Executor"/>
                <dxg:TreeListColumn FieldName="State"/>
            </dxg:TreeListControl.Columns>
            <dxg:TreeListControl.View>
                <dxg:TreeListView  
                    TreeDerivationMode="ChildNodesSelector" 
                    ChildNodesPath="Tasks"
                    CellEditorValueChangingCommand="{Binding StateChangingCommand}"/>
            </dxg:TreeListControl.View>
        </dxg:TreeListControl>
    </Grid>
</ThemedWindow>
csharp
public class ViewModel : ViewModelBase {

    IMessageBoxService MessageBoxService { get { return GetService<IMessageBoxService>(); } }

    [Command]
    public void StateChanging(CellEditorValueChangingArgs args) {
        if(args.FieldName == nameof(DataItem.State)) {
            MessageResult result;
            result = MessageBoxService.ShowMessage(
                messageBoxText: "Changing the cell value will start time consuming calculations. Do you want to continue?",
                caption: "Warning",
                icon: MessageIcon.Warning,
                button: MessageButton.OKCancel,
                defaultResult: MessageResult.OK
            );
            switch(result) {
                case MessageResult.OK:
                    args.Cancel = false;
                    break;
                case MessageResult.Cancel:
                    args.Cancel = true;
                    break;
            }
        }
    }
}

See Also

TreeListView Class

TreeListView Members

DevExpress.Xpf.Grid Namespace