.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+

View.CustomizeViewShortcut Event

Occurs when the View.CreateShortcut method creates a View Shortcut for the current View.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v20.2.dll

Declaration

public event EventHandler<CustomizeViewShortcutArgs> CustomizeViewShortcut
Public Event CustomizeViewShortcut As EventHandler(Of CustomizeViewShortcutArgs)

Event Data

The CustomizeViewShortcut event's data class is CustomizeViewShortcutArgs. The following properties provide information specific to this event:

Property Description
ViewShortcut Specifies the created View Shortcut.

Remarks

Handle this event to add custom key/value pairs to View Shortcuts when they are created. Note that you should also add custom keys to the ViewShortcut.EqualsDefaultIgnoredParameters list, to ensure that they do not break built-in functionalities.

IMPORTANT

Do not modify values corresponding to keys that already exist in newly created View Shortcuts. XAF uses this information internally, and its modification may cause issues with built-in functionalities.

Follow the steps below to handle the CustomizeViewShortcut event to add a filter expression to a List View Shortcut.

  1. In the platform-agnostic Module's Setup method, subscribe to the CustomProcessShortcut event.
  2. In this event handler, create a new List View that contains filtered objects and subscribe to the CustomizeViewShortcut event.
  3. In the event handler, add the List View's filter expression with a custom key to the Shortcut.

    using DevExpress.Data.Filtering;
    using DevExpress.ExpressApp.Model;
    // ...
    public sealed partial class MainDemoModule : ModuleBase {
        public const string CustomFilterKey = "CustomFilter";
        public override void Setup(XafApplication application) {
            base.Setup(application);
            application.CustomProcessShortcut += Application_CustomProcessShortcut;
        }
        void Application_CustomProcessShortcut(object sender, CustomProcessShortcutEventArgs e) {
            XafApplication application = (XafApplication)sender;
            if(application.FindModelView(e.Shortcut.ViewId) is IModelListView && e.Shortcut.ContainsKey(CustomFilterKey)) {
                CriteriaOperator filter = CriteriaOperator.Parse(e.Shortcut[CustomFilterKey]);
                e.View = CreateFilteredView(application, e.Shortcut.ObjectClass, e.Shortcut.ViewId, filter);
                e.Handled = true;
            }
        }
        public static ListView CreateFilteredView(XafApplication application, Type objectType, string viewId, CriteriaOperator filter) {
            IObjectSpace objectSpace = application.CreateObjectSpace(objectType);
            CollectionSourceBase source = application.CreateCollectionSource(objectSpace, objectType, viewId);
            ListView listView = application.CreateListView(viewId, source, true);
            listView.CollectionSource.Criteria[CustomFilterKey] = filter;
            listView.CustomizeViewShortcut += ListView_CustomizeViewShortcut);
            return listView;
        }
        static void ListView_CustomizeViewShortcut(object sender, CustomizeViewShortcutArgs e) {
            e.ViewShortcut[CustomFilterKey] = ((ListView)sender).CollectionSource.Criteria[CustomFilterKey].ToString();
        }
        //...
    }
    
  4. In the platform-agnostic Module, create a View Controller that displays the filtered View.

    using DevExpress.Data.Filtering;
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Actions;
    // ...
    public class MyContactsController : ObjectViewController<ObjectView, Contact> {
        public MyContactsController() {
            SimpleAction action = new SimpleAction(this, "ShowManagedContacts", DevExpress.Persistent.Base.PredefinedCategory.View);
            action.SelectionDependencyType = SelectionDependencyType.RequireSingleObject;
            action.Execute += new SimpleActionExecuteEventHandler(action_Execute);
        }
        void action_Execute(object sender, SimpleActionExecuteEventArgs e) {
            Contact currentObject = (Contact)e.SelectedObjects[0];
            CriteriaOperator filter = CriteriaOperator.Parse("Manager.Oid = ?", currentObject.Oid);
            string viewId = Application.GetListViewId(typeof(Contact));
            ListView listView = MainDemoModule.CreateFilteredView(Application, typeof(Contact), viewId, filter);
            e.ShowViewParameters.CreatedView = listView;
        }
    }
    

This code changes the default behavior of WinForms and ASP.NET applications as follows:

  • A WinForms application with the MDI UI type opens List Views with the same ID and different filters in different tabs. (Default behavior: an application activates an existing tab if its List View has the same ID as a filtered View.)
  • An ASP.NET application restores a List View's filter that is set in the SimpleAction.Execute handler. This occurs when a user clicks a browser's Back button to navigate back to a previously opened List View. (Default behavior: an application resets the filter when a user navigates back from a filtered List View.)
See Also