Skip to main content
A newer version of this page is available. .

How to: Detect a Lookup List View in Code

  • 2 minutes to read

This topic demonstrates how to check if the current View is a Lookup List View. This can be useful if you want to customize Lookups only, for instance, to hide the New Action displayed below the Lookup List View.

Note

Mobile applications do not have a specific template for Lookup List Views and do not support the approach described in this topic.

Implement a View Controller that targets List Views only and override the OnActivated method. Check that the Frame.Context value is LookupControl or LookupWindow. If the condition is true, this means that the current List View is a Lookup List View.

You can now, for example, deactivate the New Action in all Lookups. Use the Frame.GetController<ControllerType> method to get the NewObjectViewController and then use the NewObjectViewController.NewObjectAction property to access the New Action.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.SystemModule;
// ...
public class DeactivateNewActionInLookupsController : ViewController<ListView> {
    protected override void OnActivated() {
        base.OnActivated();
        if (Frame.Context == TemplateContext.LookupControl || Frame.Context == TemplateContext.LookupWindow) {
            NewObjectViewController controller = Frame.GetController<NewObjectViewController>();
            if (controller != null) {
                controller.NewObjectAction.Active.SetItemValue("LookupListView", false);
            }
        }
    }
}

Run a WinForms or ASP.NET application to ensure that the New Action is deactivated in all Lookup List Views.

You can also detect a Lookup List View by its View.Id: all Lookup List Views have identifiers with the “_LookupListView” suffix by default. However, this also detects Views that were initially designed as Lookups, but are not used as Lookups.

Tip

If you want to hide the New Action for a particular Lookup List View, find the corresponding View node in the Model Editor and set the IModelView.AllowNew property to false.

See Also