Ticket Q311982
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

How to hide the New action in Lookup Property Editors

How to hide New button on ASPxLookupPropertyEditor

created 14 years ago

We have a XAF Web app with a Detail View that displays 4 lookup properties. On this detail view only, we do not want to allow Add from the lookup property editor. Typically, we accomplish this by setting AllowNew to false for the related lookup listview in the xafml designer (see screen shot). The problem with this option is that it hides the Add option for every detail view where this property is displayed.
Our first idea to solve this issue was to clone the lookup list view, set the AllowNew property for the cloned listview to false and set some attribute on the property to tell it to use our cloned lookup listview rather than the default lookup list view. However, we could not find a way to set some attribute on the property to tell it what lookup list view to use. Is this even possible?
Next, we created a custom ASPxLookupPropertyEditor (see code below), that hides the Add button. Then we added an attribute to the property to tell it what property editor to use. This method works; however, I had to try a few different ways to get it to work and am seeking your review to ensure we are doing it correctly.
In the code below I am setting the ClientVisible property to false to hide the Add button. I had tried setting the Visible property to false on the Add button however that did not work. Is setting the ClientVisible to false the best way to hide the Add button?
Property Editor code:
  [PropertyEditor(typeof(DevExpress.Xpo.IXPSimpleObject), false)]
  public class ParityASPxLookupHideAddPropertyEditor : ASPxLookupPropertyEditor
  {
    public ParityASPxLookupHideAddPropertyEditor(Type objectType, IModelMemberViewItem info) : base(objectType, info) { }
    protected override void SetupControl(WebControl control)
    {
      base.SetupControl(control);
      if (ViewEditMode == ViewEditMode.Edit)
      {
        ASPxLookupDropDownEdit aspxDropDown = control as ASPxLookupDropDownEdit;
        if (aspxDropDown != null)
        {
          ASPxButton aspxAddButton = (ASPxButton)aspxDropDown.FindControl("Add");
          if (aspxAddButton != null)
            aspxAddButton.ClientVisible = false;
        }
      }
    }
  }
Thanks for your help
John

Question:

Answers

created 14 years ago (modified 6 years ago)

Hello John,

Update: Please see solutions for the current version in the following ticket: How to hide the New action in the ASP.NET Lookup Property Editor.

Thank you for your message.
I suggest you comment out your SetupControl method and instead add the following method into your PropertyEditor:

C#
... protected override WebControl CreateEditModeControlCore() { WebControl control = base.CreateEditModeControlCore(); if (control is ASPxLookupDropDownEdit) { ASPxLookupDropDownEdit dde = (ASPxLookupDropDownEdit)control; dde.AddingEnabled = false; dde.PreRender += new EventHandler(dde_PreRender); dde.Init += new EventHandler(dde_Init); } return control; } void dde_Init(object sender, EventArgs e) { ((ASPxLookupDropDownEdit)sender).AddingEnabled = false; } void dde_PreRender(object sender, EventArgs e) { ((ASPxLookupDropDownEdit)sender).AddingEnabled = false; } ...

I hope you find this information helpful.
Thanks,
Dennis

    Comments (1)

      Hi Dennis, your suggested change worked great. Thanks

      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.