Ticket T1006659
Visible to All Users

How to save GridControl's state after refreshing GridControl

created 4 years ago (modified 4 years ago)

[DevExpress Support Team: CLONED FROM A2161: How to preserve the XtraGrid View state]

Hello,

which events do I have to use when I want to use the RefreshHelper class with the normal DevExpress Refresh Button?

I use the View.ObjectSpace.Refreshing event to call the RefreshHelper.SaveExpansionViewInfo Method which works fine and stores the expanded rows in the arrayList.

But what event can I use to call the RefreshHelper.LoadExpansionViewInfo?

I have tried View.ObjectSpace.Reloaded event and View.CollectionSource.CollectionChanged event which both did not work.

Thanks for your help!

Answers approved by DevExpress Support

created 4 years ago

Hello,

The simplest way to accomplish this task is to use events of the 'Refresh' action itself:
The ActionBase.Executing event.
The ActionBase.Executed event.

The following controller works fine in my simple example:

C#
using DevExpress.ExpressApp; using DevExpress.ExpressApp.Actions; using DevExpress.ExpressApp.Win.Editors; using DevExpress.XtraGrid.Views.Grid; using DevExpress.ExpressApp.SystemModule; using System.ComponentModel; using DevExpress.XtraGrid.Helpers; namespace dxT1006659.Module.Win.Controllers { public class CustomWinController : ViewController { RefreshHelper helper; protected override void OnActivated() { base.OnActivated(); var cnt = Frame.GetController<RefreshController>(); if(cnt != null) { cnt.RefreshAction.Executing += RefreshAction_Executing; cnt.RefreshAction.Executed += RefreshAction_Executed; } } private void RefreshAction_Executed(object sender, ActionBaseEventArgs e) { helper.LoadViewInfo(); } private void RefreshAction_Executing(object sender, CancelEventArgs e) { helper.SaveViewInfo(); } protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); GridListEditor listEditor = ((ListView)View).Editor as GridListEditor; if(listEditor != null) { GridView gridView = listEditor.GridView; helper = new RefreshHelper(gridView, "Oid"); } } } }

The result:

I attached my example for your reference. What do you think of this solution?

We look forward to your response.
Thanks,
Andrey

    Show previous comments (1)
    Anatol (DevExpress) 4 years ago

      Hello Markus,

      The RefreshHelper.LoadExpansionViewInfo method restored expanded groups in the following event handlers in my tests:

      IObjectSpace.Reloaded
      ListView.CollectionSource.CollectionChanged
      GridView.DataSourceChanged

      If this does not work in your application, please send us a sample project for research.

        Hello Anatol,

        thanks for your answer. It works with ObjectSpace.Reloaded event.

        The problem was not using the wrong event, but using the wrong column when instantiating the RefreshHelper class. I used the column which is used for grouping instead of the key column. I have changed it and now it works fine.

        Thanks for your help!

        Anatol (DevExpress) 4 years ago

          You are welcome!

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.