Skip to content

Invoke a confirmation dialog that allows users to apply or discard changes made in a cell

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/wpf-data-grid-implement-cell-editing-confirmation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPF Data Grid - Implement an Edit Cell Confirmation

This example demonstrates how to invoke a confirmation dialog that allows users to apply or discard changes made in a cell.

image

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.

Implementation Details

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();
    }
}

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Invoke a confirmation dialog that allows users to apply or discard changes made in a cell

Topics

Resources

License

Stars

Watchers

Forks