Skip to main content
A newer version of this page is available. .

NewObjectViewController.NewObjectAction Property

Provides access to the NewObjectViewController‘s New Action.

Namespace: DevExpress.ExpressApp.SystemModule

Assembly: DevExpress.ExpressApp.v19.1.dll

Declaration

public SingleChoiceAction NewObjectAction { get; }

Property Value

Type Description
SingleChoiceAction

A SingleChoiceAction object representing the New Action.

Remarks

The New Action is intended to create new objects of one of the predefined types.

Windows Forms application:

WinNewObjectViewController_New

ASP.NET application:

WebNewObjectViewController_NewAction

You can see in the images above that the New Action in a Windows Forms versus an ASP.NET application contains a different set of items. The Action’s ChoiceActionBase.Items collection is populated in the Controller’s UpdateActionState method, which is overridden in the WinNewObjectViewController and WebNewObjectViewController descendants.

In a Windows Forms application, the New Action’s Items collection is populated by two groups of items. The first one contains the current View‘s object type (see ObjectView.ObjectTypeInfo) and its descendants. The second one contains the types that are listed in the Application Model‘s IModelCreatableItems node. This node is generated automatically. The business classes that use the CreatableItemAttribute or DefaultClassOptionsAttribute are added to it. In addition, you can add a class to this node via the Model Editor.

In an ASP.NET application, the New Action’s Items collection is populated by one group of items. This group corresponds to the first group of items in the Windows Forms New Action. This group contains the current View’s object type and its descendants. This peculiarity is caused by the Web application design. Actually, there are two New Actions in an ASP.NET application. This Action is the first; and the second is the QuickCreateAction Action (see WebNewObjectViewController.QuickCreateAction).

Note

The New Action is not available in Lookup Property Editors and nested List Views that display collection properties participating in a many-to-many relationship.

WebNewObjectViewController_NewRootObjectAction

The QuickCreateAction Action contains items that represent types listed in the Application Model’s IModelCreatableItems node, which correspond to the second group in the Windows Forms New Action. So, the New and Quick create Actions in an ASP.NET application are combined into the New Action in a Windows Forms application.

You can modify the Items collection of the Windows Forms New Action, the ASP.NET New Action and the Quick create Actions by using one of the following techniques:

  • To modify the Items collection when the current View’s object type and its descendants are added to it, handle the NewObjectViewController.CollectDescendantTypes event of the NewObjectViewController, WinNewObjectViewController or WebNewObjectViewController Controller.
  • To modify the Items collection when the types listed in the CreatableItems node are added to it, handle the NewObjectViewController.CollectCreatableItemTypes event of the NewObjectViewController, WinNewObjectViewController or WebNewObjectViewController Controller.
  • To modify the Items collection after it has been populated, override the UpdateActionState method in the WinNewObjectViewController and/or WebNewObjectViewController class descendant(s).

The New Action is active (visible) under the following conditions:

  • The current View is root (see View.IsRoot) or the current View represents the “Many” part of the One-to-Many relationship.
  • The IModelView.AllowNew property in returns true.
  • The Items collection contains at least one active item.

An item can be missing from the Items collection if the Session-specific constructor is missing in the XPO class. An item can be deactivated if the applied Security System prohibits creating objects of the corresponding type.

To ascertain why the New Action is currently deactivated or disabled, use the DiagnosticInfo Action. If you need to change the Action’s “active” or “enabled” state in code, use its ActionBase.Active or ActionBase.Enabled property, respectively.

Information on the New and Quick create Actions is available in the Application Model‘s ActionDesign node. To access it, use the Model Editor.

Example

You can access and modify the New Action in code. For example, the code below accesses the NewObjectAction and adds it to the Quick Access Toolbar.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.SystemModule;

// ...
public class NewObjectActionController : WindowController {
    protected override void OnActivated() {
        base.OnActivated();
        NewObjectViewController newObjectViewController = Window.GetController<NewObjectViewController>();
        if(newObjectViewController != null) {
            newObjectViewController.NewObjectAction.QuickAccess = true;
        }
    }
}
See Also