Search This Blog

Tuesday, May 24, 2016

WinForms GridListEditor - How to restore values in the auto filter row

I wanted to inform you of a recent solution update for this task, which will help you restore auto filter row values for reference properties as well (previously, there might be an exception). The main change is in wrapping the GridView.GuessAutoFilterRowValuesFromFilter call into the using(var criteriaScope = View.ObjectSpace.CreateParseCriteriaScope()) {...} construction, which relies on the smart DevExpress.Data.Filtering > CriteriaOperator > UserValueParse event  handling inside our XPO/EF core libraries

using System;
using DevExpress.XtraGrid;
using DevExpress.ExpressApp;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.ExpressApp.Win.Editors;

namespace MainDemo.Module.Win {
    public class B152594 : ViewController<ListView> {
        GridListEditor gridlistEditor = null;
        protected override void OnViewControlsCreated() {
            base.OnViewControlsCreated();
            gridlistEditor = View.Editor as GridListEditor;
            if(gridlistEditor != null) {
                gridlistEditor.Grid.HandleCreated += Grid_HandleCreated;
            }
        }
        private void Grid_HandleCreated(object sender, EventArgs args) {
            GridControl grid = (GridControl)sender;
            grid.HandleCreated -= Grid_HandleCreated;
            using(var criteriaScope = View.ObjectSpace.CreateParseCriteriaScope()) {//!!!
                ((GridView)grid.MainView).GuessAutoFilterRowValuesFromFilter();
            }
        }
    }
}

After you modify the filter either by manually typing values in the topmost grid row or visually via the filter builder and reopen the form, there will be the following result in the UI:


I think your end-users will appreciate this functionality and I would be grateful to hear from you on how this works in your apps and whether there are any uncovered scenarios. Thanks! 

No comments:

Post a Comment