This example demonstrates how to invoke a confirmation dialog that allows users to apply or discard changes made in a cell.
Handle the GridViewBase.ValidateCell event (raised before the modified value is posted to the cell) and display a MessageBox with a confirmation message. If a user clicks No, call the DataViewBase.HideEditor method to discard changes.
You can implement a custom attached behavior to interact with events and methods of a UI element (TableView in this example) according to the MVVM pattern:
<dxg:GridControl.View>
<dxg:TableView>
<dxmvvm:Interaction.Behaviors>
<local:EditCellConfirmationBehavior/>
</dxmvvm:Interaction.Behaviors>
</dxg:TableView>
</dxg:GridControl.View>public class EditCellConfirmationBehavior : Behavior<TableView> {
protected override void OnAttached() {
base.OnAttached();
AssociatedObject.ValidateCell += AssociatedObject_ValidateCell;
}
private void AssociatedObject_ValidateCell(object sender, GridCellValidationEventArgs e) {
if (e.Column.FieldName == nameof(Item.Growth) &&
MessageBox.Show("Do you wish to update the value?", "Confirmation", MessageBoxButton.YesNo) ==
MessageBoxResult.No) {
AssociatedObject.HideEditor();
}
}
protected override void OnDetaching() {
AssociatedObject.ValidateCell -= AssociatedObject_ValidateCell;
base.OnDetaching();
}
}- MainWindow.xaml (VB: MainWindow.xaml)
- MainViewModel.cs (VB: MainViewModel.vb)
- EditCellConfirmationBehavior.cs (VB: EditCellConfirmationBehavior.vb)
(you will be redirected to DevExpress.com to submit your response)
