How to: Customize the New Action's Items List

This topic demonstrates how to access the list of business classes added to the NewObjectViewController.NewObjectAction items list in WinForms and ASP.NET 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.

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports DevExpress.ExpressApp
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.ExpressApp.SystemModule

Namespace CustomizeNewActionItemsListExample.Module.Controllers
    Public Class CustomizeNewActionItemsListController
        Inherits ObjectViewController(Of ObjectView, Task)

        Protected Overrides Sub OnActivated()
            MyBase.OnActivated()
            Dim controller As NewObjectViewController = Frame.GetController(Of NewObjectViewController)()
            If controller IsNot Nothing Then
                AddHandler controller.CollectCreatableItemTypes, AddressOf NewObjectViewController_CollectCreatableItemTypes
                AddHandler controller.CollectDescendantTypes, AddressOf NewObjectViewController_CollectDescendantTypes
                If controller.Active Then
                    controller.UpdateNewObjectAction()
                End If
            End If
        End Sub
        Private Sub NewObjectViewController_CollectDescendantTypes(ByVal sender As Object, ByVal e As CollectTypesEventArgs)
            CustomizeList(e.Types)
        End Sub
        Private Sub NewObjectViewController_CollectCreatableItemTypes(ByVal sender As Object, ByVal e As CollectTypesEventArgs)
            CustomizeList(e.Types)
        End Sub
        Private Sub CustomizeList(ByVal types As ICollection(Of Type))
            Dim unusableTypes As New List(Of Type)()
            For Each item As Type In types
                If item Is GetType(Task) Then
                    unusableTypes.Add(item)
                End If
            Next item
            For Each item As Type In unusableTypes
                types.Remove(item)
            Next item
        End Sub
        Protected Overrides Sub OnDeactivated()
            Dim controller As NewObjectViewController = Frame.GetController(Of NewObjectViewController)()
            If controller IsNot Nothing Then
                RemoveHandler controller.CollectCreatableItemTypes, AddressOf NewObjectViewController_CollectCreatableItemTypes
                RemoveHandler controller.CollectDescendantTypes, AddressOf NewObjectViewController_CollectDescendantTypes
            End If
            MyBase.OnDeactivated()
        End Sub
    End Class
End Namespace
See Also