Ticket T736946
Visible to All Users

How to hide the New action in Lookup Property Editors

created 6 years ago (modified 6 years ago)

Hello to all,
XAF my application. Ver 18.2.8. in use web project.
I migrated xaf 17.2.9 vs 18.2.8 bat many problems related to Frame is Null.
this code has always worked well, it's a controller that will disable the "New" action button in the "LookupProperty" in the main DetailView .

C#
if (this.View.Id.Contains("RdL_DetailView") && this.View.ViewEditMode == ViewEditMode.Edit) if (this.View.FindItem("Categoria") != null) {// if (!(this.View.FindItem("Categoria").GetType().Name.Contains("ProtectedContent"))) { ViewItem property_Problema_g = this.View.FindItem("Categoria"); if (property_Problema_g is DevExpress.ExpressApp.Web.Editors.ASPx.ASPxLookupPropertyEditor) if (((DevExpress.ExpressApp.Web.Editors.ASPx.ASPxLookupPropertyEditor)(property_Problema_g)).Frame != null) { NewObjectViewController newObjDetailViewControllerWeb = ((DevExpress.ExpressApp.Web.Editors.ASPx.ASPxLookupPropertyEditor) (property_Problema_g)).Frame.GetController<NewObjectViewController>(); //newObjDetailViewControllerWeb.ObjectCreated += RdL_DetailView_Gestione_Problema_controler_ObjectCreated; newObjDetailViewControllerWeb.Active.SetItemValue("New", false); } else { ((DevExpress.ExpressApp.Web.Editors.ASPx.ASPxLookupPropertyEditor)(property_Problema_g)).InitializeFrame(); NewObjectViewController newObjDetailViewControllerWeb = ((DevExpress.ExpressApp.Web.Editors.ASPx.ASPxLookupPropertyEditor) (property_Problema_g)).Frame.GetController<NewObjectViewController>(); //newObjDetailViewControllerWeb.ObjectCreated += RdL_DetailView_Gestione_Problema_controler_ObjectCreated; newObjDetailViewControllerWeb.Active.SetItemValue("New", false); } } }
Comments (2)
AN AN
Andrea Novelli 6 years ago

    see Attachment. I would like to disable this button,
    how can i do that from code, and how can i do that from module?

    AN AN
    Andrea Novelli 6 years ago

      this is mai controller,
      and in debuger have Frame value is null.
      also after ".InitializeFrame ();"

      Answers approved by DevExpress Support

      created 6 years ago (modified 3 years ago)

      Hello Andrea,

      Please use one of the following solutions to accomplish this task:

      All platforms

      1. Change the AllowNew property in the Application Model, as described in the following ticket:
        Disable the NEW-Button for one LookupView with one Object.

      2. Create a View Controller for the lookup ListView and check to which property it belongs using the NestedFrame.ViewItem property, as shown in the following tickets:
        Conditionally lookupview new button disable
        Hide Add New button in lookup property editors

      ASP.NET WebForms

      1. Change the ASPxLookupDropDownEdit.AddingEnabled property, as shown in the following ticket:
        Change ClientVisible in newButton of ASPxLookupPropertyEditor

      2. Use the PropertyEditor.ValueRead event to access the nested Frame:

      C#
      using System; using DevExpress.ExpressApp; using DevExpress.ExpressApp.SystemModule; using DevExpress.ExpressApp.Web.Editors.ASPx; using MainDemo.Module.BusinessObjects; namespace MainDemo.Module.Web { public class WebViewController1 : ObjectViewController<DetailView, Contact> { ASPxLookupPropertyEditor managerLookup; protected override void OnActivated() { base.OnActivated(); managerLookup = View.FindItem("Manager") as ASPxLookupPropertyEditor; if (managerLookup != null) { managerLookup.ValueRead += WebViewController1_ValueRead; } } private void WebViewController1_ValueRead(object sender, EventArgs e) { if (managerLookup.Frame != null) { managerLookup.Frame.GetController<NewObjectViewController>().NewObjectAction.Active["asd"] = false; } } protected override void OnDeactivated() { base.OnDeactivated(); if (managerLookup != null) { managerLookup.ValueRead -= WebViewController1_ValueRead; managerLookup = null; } } } }

      This approach is similar to your previous solution. But, this behavior is not documented and can be changed in the future.

      Let me know if you encounter any difficulty.

        Show previous comments (1)
        Anatol (DevExpress) 6 years ago

          I am happy to hear that. The answer can be helpful to other customers. May I make this ticket public?

          AN AN
          Andrea Novelli 6 years ago

            SI ok?

            Dennis Garavsky (DevExpress) 6 years ago

              Thank you, Andrea. Published.

              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.