Skip to main content
All docs
V25.2
  • 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

    Declaration

    public ICommand<CellEditorValueChangingArgs> CellEditorValueChangingCommand { get; set; }

    Property Value

    Type Description
    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):

    <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>
    
    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