Ticket T711505
Visible to All Users

Hide Add New button in lookup property editors

created 6 years ago (modified 6 years ago)

In my ASP.NET solution, I extended IModelMember with a property that hides the Add New button on lookup property editors. This worked in DevExpress 17.1, but it does not work in 18.2, because the Frame property in the controller below is now always null. Is there another way to get to that object?

If you use DevExpress 17.1 with the attached sample project, it should work, but if you use 18.2, it won't work.

C#
public class MemberExtensionsController : ViewController<DetailView> { protected override void OnActivated() { base.OnActivated(); foreach (var editor in View.Items.OfType<ASPxLookupPropertyEditor>()) { if (!((ICustomMemberExtension)editor.Model.ModelMember).LookupAllowAdd) editor.ControlCreated += LookupPropertyEditor_ControlCreated_DisableAllowNew; } } private void LookupPropertyEditor_ControlCreated_DisableAllowNew(object sender, EventArgs e) { var frame = ((ASPxLookupPropertyEditor)sender).Frame; if (frame != null) { var controller = frame.GetController<NewObjectViewController>(); if (controller != null) controller.NewObjectAction.Active.SetItemValue("Lookup_AllowNew", false); } } }
Comments (1)
Andrey K (DevExpress Support) 6 years ago

    Hello,

    Please give us additional time to research your project. We will notify you once we have any news.

    Thanks,
    Andrey

    Answers approved by DevExpress Support

    created 6 years ago (modified 5 years ago)

    Thank you for your patience, James. The cause of the issue is that we optimized controller creation in version 17.2 for better performance. Now, the ASPxLookupPropertyEditor's Nested Frame creation is delayed.

    To resolve the issue, I suggest you access the Lookup View Item on a Detail View from a controller for the Nested Lookup List View. At this moment, it's guaranteed that the Nested Frame is created. To access the Lookup View Item for a Nested List View controller, use the NestedFrame.ViewItem property as illustrated in the How to: Initialize an Object Created Using the New Action article. The controller code will be as follows:

    C#
    public class MyViewController : ViewController<ListView> { public MyViewController() { TargetViewNesting = Nesting.Nested; } protected override void OnActivated() { base.OnActivated(); NestedFrame nestedFrame = (NestedFrame)Frame; PropertyEditor propertyEditor = nestedFrame.ViewItem as PropertyEditor; if (propertyEditor != null) { ICustomMemberExtension customMemberExtension = propertyEditor.Model.ModelMember as ICustomMemberExtension; var controller = Frame.GetController<NewObjectViewController>(); if (controller != null) controller.NewObjectAction.Active.SetItemValue("Lookup_AllowNew", customMemberExtension.LookupAllowAdd); } } }

    You can also achieve this functionality in a controller for your Detail View as Anatol described at How to hide the New action in the ASP.NET Lookup Property Editor.

      Show previous comments (3)
      DevExpress Support Team 5 years ago

        Hi ISA,

        Please make sure that your controller is activated for a Lookup List, not for a Nested List View. See: How to: Detect a Lookup List View in Code.

          Thanks Gosha !

          Now it works !

          DevExpress Support Team 5 years ago

            You are welcome, ISA!

            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.