All docs
V21.2
21.2
21.1
20.2
20.1
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Lesson 3 - Post Changes to a Database

This tutorial demonstrates how to edit data within the GridControl and save changes to the database. The tutorial is based on Lesson 2.

  1. Set the TableView.ShowUpdateRowButtons property to OnCellEditorOpen or OnCellValueChange. This turns on an edit mode that allows users to edit an entire row and then submit or cancel all changes at once:

  2. The GridControl saves changes locally and does not post them to a database. To save changes to the database, create a ValidateAndSaveCommand in the ViewModel. The command calls the data context’s SaveChanges method:

    using DevExpress.Mvvm.DataAnnotations;
    using DevExpress.Mvvm.Xpf;
    // ...
    public class ViewModel : ViewModelBase {
        NorthwindEntities northwindDBContext;
        // ...
    
        [Command]
        public void ValidateAndSave(RowValidationArgs args) {
            northwindDBContext.SaveChanges();
        }
    }
    
  3. Bind the ValidateAndSaveCommand to the GridViewBase.ValidateRowCommand property. The GridControl executes this command after a user clicks the Update button:

    <dxg:GridControl ItemsSource="{Binding Orders}">
        <!-- ... -->
        <dxg:GridControl.View>
            <dxg:TableView AutoWidth="True" 
                           BestFitModeOnSourceChange="VisibleRows"
                           ShowUpdateRowButtons="OnCellEditorOpen"
                           ValidateRowCommand="{Binding ValidateAndSaveCommand}">
            </dxg:TableView>
        </dxg:GridControl.View>
    </dxg:GridControl>
    
See Also