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: