Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • Hello,

                                    I want only enable the new and edit actions for the inline mode and without invoking a detailview,

                                    What should I do?

                                    Thanks,

                                    XinRong Liu

                                1 Solution

                                Creation Date Rating Importance Sort by
                                0

                                Hello Liu,

                                By default, when the New action is deactivated or disabled, the New Item Row feature is disabled as well. This is logical, because the New Action may be deactivated due to security reasons as well.

                                To prevent the default behavior or keep the capability to create new records directly in XAF List Editors without the New Action in the main menu, consider one of the two totally different strategies.

                                1. Deactivating the New Action and overriding the dependent ListEditor behavior.
                                1.1. Deactivate required Actions in the main menu:

                                [C#]
                                using DevExpress.ExpressApp; using DevExpress.ExpressApp.SystemModule; using DevExpress.ExpressApp.Web.SystemModule; using MainDemo.Module.BusinessObjects; namespace MainDemo.Module.Web.Controllers { public class MyViewController : ObjectViewController<ListView, Contact> { private const string UnavailableForContactActiveKey = "UnavailableForContact"; private NewObjectViewController newController = null; private ListViewController webListViewController = null; protected override void OnActivated() { base.OnActivated(); newController = Frame.GetController<NewObjectViewController>(); if(newController != null) { newController.NewObjectAction.Active.SetItemValue(UnavailableForContactActiveKey, false); } webListViewController = Frame.GetController<ListViewController>(); if(webListViewController != null) { webListViewController.EditAction.Active.SetItemValue(UnavailableForContactActiveKey, false); } } protected override void OnDeactivated() { base.OnDeactivated(); if(newController != null) { newController.NewObjectAction.Active.RemoveItem(UnavailableForContactActiveKey); } if(webListViewController != null) { webListViewController.EditAction.Active.RemoveItem(UnavailableForContactActiveKey); } } } }

                                Refer to the Task-Based Help > How to: Deactivate (Hide) an Action in Code  article for more details.

                                1.2. Subscribe to the NewItemRowListViewController.CustomCalculateNewItemRowPosition event or override the NewItemRowListViewController.CalculateNewItemRowPosition method to control the New Item Row feature availability manually:

                                [C#]
                                using DevExpress.ExpressApp; using DevExpress.ExpressApp.SystemModule; namespace MainDemo.Module.Controllers { public class MyNewItemRowListViewController : NewItemRowListViewController { protected override NewItemRowPosition CalculateNewItemRowPosition() { NewItemRowPosition result = NewItemRowPosition.None; if(View.Model != null && View.AllowEdit && View.AllowNew) { result = ((IModelListViewNewItemRow)View.Model).NewItemRowPosition; } return result; } } }

                                If you are inheriting from a system Controller, do NOT specify the TargetViewId, TargetObjectType and TargetViewNesting properties, and check the View.Id, View.ObjectType, View.IsRoot and other suitable conditions in the CalculateNewItemRowPosition method.  Refer to the Customize Controllers and Actions topic to learn how to handle controllers' events and override their methods.
                                Since you are ignoring the NewObjectViewController.NewObjectAction.Active/Enabled state completely, you may want to additionally check for security permissions and other things manually (see the UpdateActionState of the NewObjectViewController class for more details).

                                2. Hiding the New Action control in nested views without Action deactivation.

                                [C#]
                                using System.ComponentModel; using DevExpress.ExpressApp; using DevExpress.ExpressApp.SystemModule; using DevExpress.ExpressApp.Templates.ActionControls; namespace MainDemo.Module.Controllers { public class HideNewActionWithoutDeactivationViewController : ViewController { private ActionControlsSiteController actionControlsSiteController = null; private FillActionContainersController fillActionsController = null; public HideNewActionWithoutDeactivationViewController() { TargetViewId = "Contact_Tasks_ListView"; } protected override void OnActivated() { base.OnActivated(); actionControlsSiteController = Frame.GetController<ActionControlsSiteController>(); if(actionControlsSiteController != null) { actionControlsSiteController.CustomAddActionControlToContainer += ActionControlsSiteController_CustomAddActionControlToContainer; } fillActionsController = Frame.GetController<FillActionContainersController>(); if(fillActionsController != null) { fillActionsController.CustomRegisterActionInContainer += FillActionsController_CustomRegisterActionInContainer; } } private void DisableActionControlCreation(HandledEventArgs args, string actionId) { if(actionId == NewObjectViewController.NewActionId) { args.Handled = true; } } private void FillActionsController_CustomRegisterActionInContainer(object sender, CustomRegisterActionInContainerEventArgs e) { DisableActionControlCreation(e, e.Action.Id); } private void ActionControlsSiteController_CustomAddActionControlToContainer(object sender, CustomAddActionControlEventArgs e) { DisableActionControlCreation(e, e.Action.Id); } protected override void OnDeactivated() { if(actionControlsSiteController != null) { actionControlsSiteController.CustomAddActionControlToContainer -= ActionControlsSiteController_CustomAddActionControlToContainer; } if(fillActionsController != null) { fillActionsController.CustomRegisterActionInContainer -= FillActionsController_CustomRegisterActionInContainer; } base.OnDeactivated(); } } }


                                Events used in this approach are raised when the current Frame is initialized. If this Frame is a Window, the View that is about to be displayed is unknown. So, this approach cannot be used to hide the New action only in a particular root View. However, the View ID is available in nested Frames at this moment. So, this approach is suitable if you need to hide the New action in a nested ListView shown for an associated collection. For instance, in the code example, customization is applied to the Tasks ListView from the Contact DetailView (Contact_Tasks_ListView).

                                Finally, there is another, but yet more complicated strategy with deactivating the Action and overriding the ListEditor behavior in a more tricky way, where the custom Active key, e.g., "UnavailableForContact", is excluded from processing, but we would like to refrain from sharing this code due to its size and complexity.

                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2017 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners