Skip to content

DevExpress-Examples/wpf-data-grid-call-begindataupdate-and-enddataupdate-at-view-model-level

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPF Data Grid - Call the BeginDataUpdate and EndDataUpdate Methods at the View Model Level

This example demostrates how to call the BeginDataUpdate and EndDataUpdate methods in an MVVM application. These methods allow you to accumulate changes and update data within the GridControl in one action.

Follow these steps to use the methods in your application:

1. Create a custom service that allows you to call the GridControl methods.

...
public interface ICustomService {
    void BeginUpdate();
    void EndUpdate();
}

class CustomService : ServiceBase, ICustomService {
    GridControl ActuaGridControl { get { return  AssociatedObject as GridControl; } }

    //...

    public void BeginUpdate() {
        ActuaGridControl.BeginDataUpdate();
    }

    public void EndUpdate() {
       ActuaGridControl.EndDataUpdate();
    }
}
...

2. Add the service to your View and assosiate this service with the GridControl.

<dxg:GridControl>
    <mvvm:Interaction.Behaviors>
        <local:CustomService />
    </mvvm:Interaction.Behaviors>
</dxg:GridControl>
...

3. Access to the service at the View Model level. If you inherit your View Model class from ViewModelBase, you can access to the service as follows:

public class ViewModel : ViewModelBase {
    //...
    
    public ICustomService CustomService { get { return this.GetService<ICustomService>(); } }
    
    [Command]
    public void UpdateSource() {
        CustomService.BeginUpdate();
        foreach(DataItem item in Source) {
            item.Value = random.Next(Source.Count);
        }
        CustomService.EndUpdate();
    }
}

If you use Generated View Models or Custom View Models, refer to the following topics:

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)