Skip to main content
.NET 6.0+

How to: Customize the New Action's Items List

  • 3 minutes to read

This topic demonstrates how to access the list of business classes added to the NewObjectViewController.NewObjectAction items list in WinForms and ASP.NET Web Forms applications with the Classic Web UI.

Generally, you can use the NewObjectViewController.NewObjectActionItemListMode property to choose the predefined mode of populating the New Action item list. If modes listed in the NewObjectActionItemListMode enumeration do not fit your requirements, proceed to see how to populate the list manually.

To customize the New Action’s Items list, handle the NewObjectViewController.CollectDescendantTypes and NewObjectViewController.CollectCreatableItemTypes events of the NewObjectViewController, which contains the New Action. The former event is raised when the current object type and its descendants are added to the Action’s Items list, and the latter is raised when all the remaining types whose CreatableItem property is set to true in the Application Model (see IModelBOModel) are added. In the example below, the Task item is removed.

Note that in ASP.NET Core Blazor and ASP.NET Web Forms applications with the New Web UI, this Controller hides the New Action from the Task Views.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.ExpressApp;
using DevExpress.Persistent.BaseImpl;
using DevExpress.ExpressApp.SystemModule;

namespace CustomizeNewActionItemsListExample.Module.Controllers {
    public class CustomizeNewActionItemsListController : ObjectViewController<ObjectView, Task> {
        protected override void OnActivated() {
            base.OnActivated();
            NewObjectViewController controller = Frame.GetController<NewObjectViewController>();
            if (controller != null) {
                controller.CollectCreatableItemTypes += NewObjectViewController_CollectCreatableItemTypes;
                controller.CollectDescendantTypes += NewObjectViewController_CollectDescendantTypes;
                if (controller.Active) {
                    controller.UpdateNewObjectAction();
                }
            }
        }
        private void NewObjectViewController_CollectDescendantTypes(object sender, CollectTypesEventArgs e) {
            CustomizeList(e.Types);
        }
        private void NewObjectViewController_CollectCreatableItemTypes(object sender, CollectTypesEventArgs e) {
            CustomizeList(e.Types);
        }
        private void CustomizeList(ICollection<Type> types) {
            List<Type> unusableTypes = new List<Type>();
            foreach (Type item in types) {
                if (item == typeof(Task)) {
                    unusableTypes.Add(item);
                }
            }
            foreach (Type item in unusableTypes) {
                types.Remove(item);
            }
        }
        protected override void OnDeactivated() {
            NewObjectViewController controller = Frame.GetController<NewObjectViewController>();
            if (controller != null) {
                controller.CollectCreatableItemTypes -= NewObjectViewController_CollectCreatableItemTypes;
                controller.CollectDescendantTypes -= NewObjectViewController_CollectDescendantTypes;
            }
            base.OnDeactivated();   
        }
    }
 }
See Also