GridViewBase.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
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 GridControl does not execute a command bound to CellValueChangingCommand when you change a cell editor’s 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:GridControl ...>
<dxg:GridControl.View>
<dxg:TableView ...
CellEditorValueChangingCommand="{Binding NumberChangingCommand}"/>
</dxg:GridControl.View>
</dxg:GridControl>
</Grid>
</ThemedWindow>
public class ViewModel : ViewModelBase {
IMessageBoxService MessageBoxService { get { return GetService<IMessageBoxService>(); } }
[Command]
public void NumberChanging(CellEditorValueChangingArgs args) {
if(args.FieldName == nameof(DataItem.Number)) {
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;
}
}
}
}