Ticket T116723
Visible to All Users

ASPxLookupPropertyEditor - How to add an Edit or View button to the combo box

created 11 years ago

Hi All

We would like to give the users a button next to the New and Reset buttons near the dropdownlists in detailview edit mode.

An example would be a View Button to a Job Profile dropdownlist where the user can get a view of the description of the job profile.

Regards,
Deven

Answers approved by DevExpress Support

created 11 years ago (modified 5 years ago)

Hello Deven,

v18.1+
The built-in ASPxGridLookupPropertyEditor provides the Edit button out of the box. You can select this Property Editor Type for your reference properties in the Model Editor of your Web module or project.

Previous solutions:

You can use the ASPxObjectPropertyEditor to edit the referenced object. Please refer to a similar ticket: ASPxLookupPropertyEditor: we have New/Clear but no edit.

Alternatively, open the DetailView in a View mode and click on the hyperlink displayed instead of the lookup editor.

Finally, you can create an ASPxLookupPropertyEditor's descendant and add a custom button to it. Here is an example (we no longer maintain it and there may be issues in newer versions like in t897882):

v15.1 (v2015 vol 1) and higher:

C#
using System; using System.Web.UI.WebControls; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Actions; using DevExpress.ExpressApp.Editors; using DevExpress.ExpressApp.Model; using DevExpress.ExpressApp.Utils; using DevExpress.ExpressApp.Web; using DevExpress.ExpressApp.Web.Editors.ASPx; using DevExpress.Persistent.Base; using DevExpress.Web; namespace MainDemo.Module.Web { [PropertyEditor(typeof(object), false)] public class ASPxLookupPropertyEditorWithEdit : ASPxLookupPropertyEditor { public ASPxLookupPropertyEditorWithEdit(Type objectType, IModelMemberViewItem model) : base(objectType, model) { } PopupWindowShowAction editObjectAction; protected override WebControl CreateEditModeControlCore() { WebControl control = base.CreateEditModeControlCore(); ASPxButtonEditBase buttonEdit; if (UseFindEdit()) { buttonEdit = FindEdit.Editor; } else { buttonEdit = DropDownEdit.DropDown; } if (editObjectAction == null) { editObjectAction = new PopupWindowShowAction(null, MemberInfo.Name + "_ASPxLookupEditor_EditObject", PredefinedCategory.Unspecified); editObjectAction.CustomizePopupWindowParams += editObjectAction_CustomizePopupWindowParams; editObjectAction.Application = application; } EditButton editButton = new EditButton(); ASPxImageHelper.SetImageProperties(editButton.Image, "Editor_Edit", 16, 16); buttonEdit.Buttons.Add(editButton); buttonEdit.Load += new EventHandler(buttonEdit_Load); return control; } void buttonEdit_Load(object sender, EventArgs e) { ASPxButtonEditBase buttonEdit = (ASPxButtonEditBase)sender; string showModalWindowScript = application.PopupWindowManager.GetShowPopupWindowScript(editObjectAction, null, buttonEdit.ClientID, false, editObjectAction.IsSizeable, false, false, "function() { s.cpLockButtonClick = false; }"); ButtonEditClientSideEventsBase clientSideEvents = (ButtonEditClientSideEventsBase)buttonEdit.GetClientSideEvents(); int index = clientSideEvents.ButtonClick.LastIndexOf("}"); string script = String.Format("if(e.buttonIndex == 2 && s.GetText() != '{0}') {{ {1} e.handled = true; e.processOnServer = false; }}", CaptionHelper.NullValueText, showModalWindowScript); clientSideEvents.ButtonClick = clientSideEvents.ButtonClick.Insert(index, script); } void editObjectAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) { IObjectSpace editObjectSpace = objectSpace.CreateNestedObjectSpace(); DetailView view = application.CreateDetailView(editObjectSpace, editObjectSpace.GetObject(GetControlValueCore())); view.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit; e.View = view; e.DialogController.SaveOnAccept = true; } } }

Before v15.1 (v2015 vol 1):

C#
[PropertyEditor(typeof(object), false)] public class ASPxLookupPropertyEditorWithEdit : ASPxLookupPropertyEditor { public ASPxLookupPropertyEditorWithEdit(Type objectType, IModelMemberViewItem model) : base(objectType, model) { } ASPxButton editButton; PopupWindowShowAction editObjectAction; protected override WebControl CreateEditModeControlCore() { WebControl control = base.CreateEditModeControlCore(); foreach (Control editor in control.Controls) { if (editor is ASPxLookupFindEdit && UseFindEdit() || editor is ASPxLookupDropDownEdit && !UseFindEdit()) { if (editObjectAction == null) { editObjectAction = new PopupWindowShowAction(null, MemberInfo.Name + "_ASPxLookupEditor_EditObject", PredefinedCategory.Unspecified); editObjectAction.CustomizePopupWindowParams += new CustomizePopupWindowParamsEventHandler(editObjectAction_CustomizePopupWindowParams); editObjectAction.Application = application; } editButton = RenderHelper.CreateASPxButton(); editButton.ID = "EditRecord"; editButton.CssClass = "xafLookupButton"; string showModalWindowScript = application.PopupWindowManager.GenerateModalOpeningScript((WebControl)editor, editObjectAction, WindowWidth, WindowHeight, false, String.Empty); editButton.ClientSideEvents.Click = "function(sender, e) { " + showModalWindowScript + "; e.handled = true; e.processOnServer = false; }"; ASPxImageHelper.SetImageProperties(editButton.Image, "Action_Edit_12x12"); TableCell newCell = new TableCell(); newCell.Attributes["align"] = "right"; newCell.Attributes["valign"] = "middle"; newCell.Controls.Add(editButton); ((Table)editor).Rows[0].Cells.Add(newCell); editor.Init += new EventHandler(editor_Init); } } return control; } void editor_Init(object sender, EventArgs e) { if (!ImmediatePostData) { if (sender is ASPxLookupFindEdit) { string script = String.Format("function(s, e) {{ {0}.SetEnabled(s.GetText() != '{1}'); }}", editButton.ClientID, CaptionHelper.NullValueText); ((ASPxLookupFindEdit)sender).TextBox.ClientSideEvents.ValueChanged = script; } else if (sender is ASPxLookupDropDownEdit) { string script = String.Format("function(s, e) {{ {0}.SetEnabled(s.GetSelectedIndex() != 0); e.processOnServer = false; }}", editButton.ClientID); ((ASPxLookupDropDownEdit)sender).DropDown.ClientSideEvents.SelectedIndexChanged = script; } } } protected override void ReadEditModeValueCore() { base.ReadEditModeValueCore(); if (editButton != null) { editButton.ClientEnabled = PropertyValue != null; } } void editObjectAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) { IObjectSpace editObjectSpace = objectSpace.CreateNestedObjectSpace(); DetailView view = application.CreateDetailView(editObjectSpace, editObjectSpace.GetObject(GetControlValueCore())); view.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit; e.View = view; e.DialogController.SaveOnAccept = true; } }

Refer to the Implement Custom Property Editors.topic for additional information.

Please let me know if you have difficulties with any of these solutions.

    Show previous comments (24)
    Andrey K (DevExpress Support) 5 years ago

      Hello,

      I've created a separate ticket on your behalf (T834279: How to assign an image). It has been placed in our processing queue and will be answered shortly.

      Thanks,
      Andrey

      KY KY
      Kalem Yazılım 5 years ago

        Hello Dear Andrey,

        Thanks for new topic, I have a new question,

        I set this button for my LookupPropertyEditor default. But when i clicked a null LookupPropertyEditor, It gets error because GetControlValueCore() gets null. When i null control for this, i get CustomizePopupWindowParams.View error.

        How can i solve this problem ?

        Thanks for your assistance

        DevExpress Support Team 5 years ago

          Hello Kalem,

          I've created a separate ticket on your behalf (T834340: How to cancel PopupWindowShowAction based on a condition). It has been placed in our processing queue and will be answered shortly.

          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.