Ticket T186503
Visible to All Users

Disable New action, but not Save&New

created 10 years ago

When I enable the Save&New action in a detail view, the New action is automatically enabled (and shown) as well. Is there a way to hide/disable the New action? I only want my users to be able to do Save&New and Save&Close. The New action asks for a save confirmation, but even if I say "no", the old object lingers and gets saved (incompletely) in the parent object space once the detail view's nested object space is committed. I could, of course, cancel the action once pressed, but I'd rather not have it show up in the first place.

Comments (2)
SK SK
Serge K (DevExpress) 10 years ago

    Hi Steven,

    >>When I enable the Save&New action in a detail view, the New action is automatically enabled (and shown) as well.
    This behavior is by design. There is a way to deactivate any action by updating its Active collection, but we do not recommend doing it in this case.

    >>The New action asks for a save confirmation, but even if I say "no", the old object lingers and gets saved (incompletely) in the parent object space once the detail view's nested object space is committed.
    Can you provide a simple solution to reproduce the behavior your described above?  All changes in the object space should be rolled back after an end-user presses the "No" button in the confirmation dialog.  Possibly, there is an issue in your code, and we will check for a way to override it.

      I tried the Active collection, and the effect was that it also disabled the Save&New action. Re-enabling it via SaveAndNewAction.Active.RemoveItem("NewObjectAction is active") did not seem to work. What am I doing wrong?
      I fail to see the utility of forcing both actions to show simultaneously, with no way of turning the New action off. It is confusing to my users, who try New when they mean Save&New, and get confused about the Save prompt they get.
      As usual, extracting a solution requires significant effort, I'll try to find the problem on my own first.

      Answers approved by DevExpress Support

      created 10 years ago (modified 9 years ago)

      Hi Steven,

      The best way to hide an Action from an ActionContainer is to handle the CustomizeContainerActions event of the FillActionContainersController and ActionControlsSiteController controllers. This events allows you to remove any action from any ActionContainer. You can use the following example controller to hide the New action and use the Save&New action.

      C#
      public class TestController : WindowController { protected override void OnActivated() { base.OnActivated(); this.Frame.GetController<FillActionContainersController>().CustomizeContainerActions += TestController_CustomizeContainerActions; this.Frame.GetController<ActionControlsSiteController>().CustomizeContainerActions += TestController_CustomizeContainerActions; } void TestController_CustomizeContainerActions(object sender, CustomizeContainerActionsEventArgs e) { if (e.Category == "ObjectsCreation") { ActionBase action = e.AllActions.Find("New"); if (action != null) { e.ContainerActions.Remove(action); } } } }
        Show previous comments (5)
        Dennis Garavsky (DevExpress) 9 years ago

          Thanks for your update, Adrian.
          >>Sorry, that didn't work either.
          The application does not automatically switch to the new templates. Please clarify what you have done and tested, because it is unclear whether you set the WinApplication.UseOldTemplates property to False (it is required for this code to work) and what was the result of this action in your project.

          Our approach is recommended, and we do not provide another solution for this task. We will wait for your example and will be more than happy to research it. Thanks.

            Thank you for your reply. I have set WinApplication.UseOldTemplates=false as instructed.
            I just noticed that Serge's answer specifies a WindowController, not a ViewController. I have now implemented it as such, but I hit a wall:

            1. Even if I leave the controller exactly as in Serge's example, to apply to all windows, the CustomizeContainerActions handler still never gets triggered. The handlers are correctly added to the controllers, and the controllers are active (I checked this with a breakpoint in OnActivated).
            2. I need this to apply only to some of my DetailViews (which I pick in OnActivated), not to all Windows in my application.
              Is there a solution for Views instead of Windows? Or a way to determine the View from a Window, since I pick the views I want this done in based on their ID? I basically need a way to only hide the New button in some, but not all of my application's Views/Windows.
            Dennis Garavsky (DevExpress) 9 years ago

              Thanks for your clarification.
              A1: We cannot suggest a solution based on this information. We will wait for your example and be more than happy to research it.
              A2: The Window/Frame.View property should provide you with the information you are looking for. It is important to note, however, that the View property can be initialized later in the form's life cycle.
              I have just thought that since you need it for specific Views only, it may be easier for you to completely deactivate the standard New and Save And New Actions for these Views via a custom ViewController and then develop your own Save And New Action. This is a bit more work, but the solution looks clearer to me. I do not want to advise to you handling this task at the WinForms BarManager level at this stage because it looks even more difficult.

              Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

              Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.