Skip to content

Contains solutions that extend CRUD operations (undo operations, async operations, detail collection editing)

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/wpf-data-grid-extend-crud-operations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPF Data Grid - Extend CRUD Operations

After you bind the Data Grid to a database, you can implement CRUD operations (create, read, update, delete). These operations allow you to post changes that users make in the Data Grid to the database.

This repository contains solutions that extend CRUD operations:

Solution 1 - Undo Operations

This solution uses the UndoCRUDOperationsBehavior that allows users to undo the latest operation (create, update, or delete).

  1. Assign this behavior to the Data Grid's view.

  2. Create a class that implements ICopyOperationsSupporter. The class instance allows the behavior to copy data item properties and apply them when users execute the undo operation.

    <dxg:GridControl x:Name="grid" ItemsSource="{Binding ItemsSource}">
        <dxg:GridControl.View>
            <dxg:TableView>
                <!-- ... -->
                <dxmvvm:Interaction.Behaviors>
                    <local:UndoCRUDOperationsBehavior x:Name="undoBehavior" 
                        CopyOperationsSupporter="{Binding CopyOperationsSupporter}" />
                </dxmvvm:Interaction.Behaviors>
            </dxg:TableView>
        </dxg:GridControl.View>
    </dxg:GridControl>
    public interface ICopyOperationSupporter {
        object Clone(object item);
        void CopyTo(object source, object target);
    }
  3. Allow users to call the behavior's UndoCommand.

    <dxb:BarButtonItem Content="Undo (Ctrl+Z)" Command="{Binding UndoCommand, ElementName=undoBehavior}"/>

Files to Look At

Solution 2 - Async CRUD Operations

This solution shows how to implement async CRUD operations:

  1. Create tasks that allow the Data Grid to work with the database asynchronously.
  2. Assign these tasks to the DataSourceRefreshArgs.RefreshAsync, ValidationArgs.ResultAsync, DeleteValidationArgs.ResultAsync properties.
args.ResultAsync = Task.Run(async () => { await DoSomethingAsync(); });

Note that you also need to load initial data asynchronously. Use the EventToCommand behavior to execute the RefreshDataSource command in response to the Loaded event:

<dxg:GridControl ItemsSource="{Binding ItemsSource}">
    <dxmvvm:Interaction.Behaviors>
        <dxmvvm:EventToCommand Event="Loaded" 
                               Command="{Binding RelativeSource={RelativeSource Self}, 
                                                 Path=AssociatedObject.View.Commands.RefreshDataSource}"/>
    </dxmvvm:Interaction.Behaviors>
    <!-- ... -->
</dxg:GridControl>

Files to Look At

Solution 3 - Detail Collection Editing

The solution uses the DialogEditFormBehavior with a custom EditTemplate that allows users to edit detail data for each row in the Data Grid.

Files to Look At

Documentation

More Examples

Does this example address your development requirements/objectives?

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

About

Contains solutions that extend CRUD operations (undo operations, async operations, detail collection editing)

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •