Ticket T587910
Visible to All Users

Change ClientVisible in newButton of ASPxLookupPropertyEditor

created 7 years ago

I have an ASPxLookupPropertyEditor with the new button… I need to disable it.
I can hide it but not disable it, could you help me ?

end result should be a dimmed New action on all my lk up controls on a DetailView

this is what I have:

protected override void OnViewControlsCreated()
        {
            base.OnViewControlsCreated();

foreach (var item in  View.Items)
            {
                if (item is ASPxLookupPropertyEditor)
                {
                    var fld = item as ASPxLookupPropertyEditor;
                    fld.DropDownEdit.NewButton.ClientVisible = false; //<=====HERE, how to disable and show it.
                }
            }
        }

Thanks for the help.

Comments (1)
TV TV
Thomas Vetterling 7 years ago

    Hello Raumnz,

    you could write a Controller for that…

    C#
    public abstract partial class DeactivateNewActionInLookupsController : ViewController { public DeactivateNewActionInLookupsController() { InitializeComponent(); RegisterActions(components); TargetViewType = ViewType.ListView; } protected abstract bool IsLookupTemplate(); protected override void OnFrameAssigned() { base.OnFrameAssigned(); Frame.TemplateChanged += Frame_TemplateChanged; } public virtual void HideNewAction(object sender) { if (IsLookupTemplate()) { bool bActive = false; if (sender is NestedFrame h) { //depending on View and Control you can determine whether the 'new' button should be visible or not if (h.ViewItem.ObjectTypeInfo.FullName == "WPS5.Module.BusinessObjects.WPSGroup") { if (h.ViewItem.Id == "Baugruppe") { bActive = true; } } var controller = Frame.GetController<NewObjectViewController>(); controller.NewObjectAction.Active.SetItemValue("LookupListView", bActive); } } private void Frame_TemplateChanged(object sender, EventArgs e) { HideNewAction(sender); } protected override void OnDeactivated() { base.OnDeactivated(); Frame.TemplateChanged -= Frame_TemplateChanged; } }

    This controller is abstract because the

    C#
    IsLookupTemplate() function is platform dependent. So you need also platform dependent controllers, which implement this function.

    WINDOWS:

    C#
    protected override bool IsLookupTemplate() { return Frame.Template is ILookupPopupFrameTemplate; }

    WEB:

    C#
    protected override bool IsLookupTemplate() { var page = Frame.Template as BaseXafPage; if (page != null) return page.TemplateContent is ILookupPopupFrameTemplate; return false; }

    Yours
    Thomas

    Answers approved by DevExpress Support

    created 7 years ago (modified 7 years ago)

    Hello Raumnz,

    As far as I understand, you want to disable the lookup editor's New button instead of hiding it. To accomplish this task, set the EditButton.Enabled property at an appropriate moment (after XAF changes it based on the ASPxLookupDropDownEdit.AddingEnabled property). Here is an example:

    C#
    using System; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Web.Editors.ASPx; namespace MainDemo.Module.Web { public class DisableNewInLookupController : ViewController<DetailView> { protected override void OnActivated() { base.OnActivated(); foreach(ASPxLookupPropertyEditor lookupPropertyEditor in View.GetItems<ASPxLookupPropertyEditor>()){ lookupPropertyEditor.ControlCreated += lookupPropertyEditor_ControlCreated; } } void lookupPropertyEditor_ControlCreated(object sender, EventArgs e) { ASPxLookupDropDownEdit dropDownEdit = ((ASPxLookupPropertyEditor)sender).DropDownEdit; if (dropDownEdit != null) { dropDownEdit.PreRender += dropDownEdit_PreRender; } } void dropDownEdit_PreRender(object sender, EventArgs e) { ASPxLookupDropDownEdit dropDownEdit = (ASPxLookupDropDownEdit)sender; dropDownEdit.PreRender -= dropDownEdit_PreRender; dropDownEdit.NewButton.Enabled = false; } protected override void OnDeactivated() { base.OnDeactivated(); foreach (ASPxLookupPropertyEditor lookupPropertyEditor in View.GetItems<ASPxLookupPropertyEditor>()) { lookupPropertyEditor.ControlCreated -= lookupPropertyEditor_ControlCreated; } } } }

    Is this what you were looking for?

      Comments (2)

        yes Anatol exactly, thanks so much Anatol, it works good.

        also, thanks to Thomas Vetterling for the controller code i will keep it in mind.

        Anatol (DevExpress) 7 years ago

          You are welcome!

          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.