Ticket T304667
Visible to All Users

XAF - How to completely disable adding and removing fields in the layout customization form (DetailView) or grid's Column Chooser (ListView)

created 9 years ago (modified 9 years ago)

Hi,

I would like to remove the Add/Remove button from the ColumnChooser for some views.
Is below the best way to achieve this?

C#
public sealed class CustomGridListEditorColumnChooserExtender : GridListEditorColumnChooserExtender { public CustomGridListEditorColumnChooserExtender(IModelListView listViewModel, WinColumnsListEditor listEditor, ITypeInfo objectTypeInfo, GridView gridView) : base(listViewModel, listEditor, objectTypeInfo, gridView) { } public override void AddButtonsToCustomizationForm() { base.AddButtonsToCustomizationForm(); this.AddButton.Visible = false; this.RemoveButton.Visible = false; } }

Regards,
Paul

Answers approved by DevExpress Support

created 2 months ago

Hello,

XAF v24.2 includes a new HideInUI attribute for use within business classes. This is a simple declarative way to hide fields from ListView and DetailView, their customization forms and many other UI contexts such as the Field List of the Filter, Report and Dashboard Editor/Designer. You no longer need manual Controller-based solutions or multiple non-flexible VisibleInXXX and Browsable attributes.

24-2-xaf-control-filed-visibility-for-various-ui-contexts-declaratively@2x.png

We also unified ways to disable runtime layout customization completely - you can now use 2 CustomizationFormEnabled options (global and View-specific) instead of the former 4 options.

Refer to the following breaking change article for more information: EnableColumnChooser and CustomizationEnabled options are replaced by a common cross-plarform option CustomizationFormEnabled.

Best regards,
Herman

    created 9 years ago (modified 6 months ago)

    These solutions prevent access to the layout customization of views at runtime for your end-users. Technically, you can remove the Column Chooser and Customization Form completely from your Grid List Editors and Layout Managers.

    In certain cases, it may be easier not to remove these runtime capabilities completely, but limit them to certain fields only. Refer to the How to hide a property/field from the grid's Column Chooser, layout's Customization Form, and Object Model dialogs in both ListView and DetailView article for more information.

    1. Customization at the Application Level

    ASP.NET Core Blazor and WinForms

    DetailView and DashboardView

    In the Application Model (in the Model Editor or in code), set one of the following options:

    ASP.NET Core Blazor and WebForms

    ListView

    In the Application Model (in the Model Editor or in code), set one of the following options:

    2. Dynamic Control Customization in Code

    To remove customization forms completely, you can add custom XAF controllers to your XAF projects. Optionally, you can limit these global customizations to a certain View only or based on the current user.

    You can also control visibility of certain properties: How to hide a property/field from the grid's Column Chooser, layout's Customization Form, and Object Model dialogs in both ListView and DetailView.

    ASP.NET Core Blazor

    ListView and DetailView

    NOTE: This code requires v24.1.2+. XAF Blazor does not support runtime layout customization for DashboardView.

    To hide the Customize button, disable the ObjectModelController before the View Controls are created:

    C#
    using DevExpress.ExpressApp; using DevExpress.ExpressApp.Blazor.SystemModule; namespace YourApplicationName.Blazor.Server.Controllers; public class DisableObjectModelController : ViewController { private ObjectModelController objectModelController; const string deactivateReason = "NoCustomizationRequired"; protected override void OnActivated() { base.OnActivated(); objectModelController = Frame.GetController<ObjectModelController>(); if (objectModelController != null) { objectModelController.Active.SetItemValue(deactivateReason, false); } } protected override void OnDeactivated() { base.OnDeactivated(); if (objectModelController != null) { objectModelController.Active.RemoveItem(deactivateReason); objectModelController = null; } } }

    WinForms

    DetailView

    1. Global. In code - use the static LayoutControl.AllowCustomizationDefaultValue property in the Main method of the SolutionName.Win/Program.xx file (in v20.1.10+, v20.2.5+).

    2. Local. In code - use the LayoutControl.AllowCustomization property inside a ViewController in the SolutioName.Module.Win project (prior to v15.1, use the LayoutControl.AllowCustomizationMenu property). For more information, see Access the Layout Control.

    C#
    using DevExpress.XtraLayout; namespace YourSolutionName.Module.Win { public class MyWinLayoutManagerController : WinLayoutManagerController { protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); ((LayoutControl)View.Control).OptionsCustomizationForm.ShowLayoutTreeView = false; } protected override void AddButtonsToCustomizationForm() { //base.AddButtonsToCustomizationForm(); } } }
    Visual Basic
    Imports DevExpress.XtraLayout Namespace YourSolutionName.Module.Win Public Class MyWinLayoutManagerController Inherits WinLayoutManagerController Protected Overrides Sub OnViewControlsCreated() MyBase.OnViewControlsCreated() CType(View.Control, LayoutControl).OptionsCustomizationForm.ShowLayoutTreeView = False End Sub Protected Overrides Sub AddButtonsToCustomizationForm() 'base.AddButtonsToCustomizationForm(); End Sub End Class End Namespace

    You will also need to add a reference to the DevExpress.XtraLayout assembly to use this controller.
    Please let me know if you need further assistance.

    ListView

    C#
    using DevExpress.ExpressApp.DC; using DevExpress.ExpressApp.Model; using DevExpress.ExpressApp.Win.Editors; using DevExpress.ExpressApp.Win.SystemModule; using DevExpress.XtraGrid.Views.Grid; namespace YourSolutionName.Module.Win { public class DisableGridListEditorColumnChooserController : GridEditorColumnChooserController { protected override GridListEditorColumnChooserExtender CreateColumnChooserExtenderCore() { //GridListEditor gridListEditor = View.Editor as GridListEditor; //if(gridListEditor != null && gridListEditor.GridView != null) { // return new MyGridListEditorColumnChooserExtender(View.Model, gridListEditor, View.ObjectTypeInfo, gridListEditor.GridView); //} return null; } //internal class MyGridListEditorColumnChooserExtender : GridListEditorColumnChooserExtender { // public MyGridListEditorColumnChooserExtender(IModelListView listViewModel, WinColumnsListEditor listEditor, // ITypeInfo objectTypeInfo, GridView gridView) : base(listViewModel, listEditor, objectTypeInfo, gridView) { // } // public override void AddButtonsToCustomizationForm() { // base.AddButtonsToCustomizationForm(); // this.AddButton.Visible = false; // this.RemoveButton.Visible = false; // } //} } }
    Visual Basic
    Imports DevExpress.ExpressApp.DC Imports DevExpress.ExpressApp.Model Imports DevExpress.ExpressApp.Win.Editors Imports DevExpress.ExpressApp.Win.SystemModule Imports DevExpress.XtraGrid.Views.Grid Namespace YourSolutionName.Module.Win Public Class DisableGridListEditorColumnChooserController Inherits GridEditorColumnChooserController Protected Overrides Function CreateColumnChooserExtenderCore() As GridListEditorColumnChooserExtender Return Nothing End Function End Class End Namespace

    DashboardView

    C#
    using DevExpress.ExpressApp; using DevExpress.ExpressApp.Win.Layout; using DevExpress.ExpressApp.Win.SystemModule; using DevExpress.XtraLayout.Customization; namespace YourSolutionName.Module.Win { public class MyWinLayoutManagerController : ViewController<DashboardView> { public MyWinLayoutManagerController() { this.TargetViewId = "TestDashboard"; } protected override void OnActivated() { base.OnActivated(); Frame.GetController<DashboardWinLayoutManagerController>().Active["T900193"] = false; } protected override void OnDeactivated() { Frame.GetController<DashboardWinLayoutManagerController>().Active.RemoveItem("T900193"); base.OnDeactivated(); } protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); var layoutControl = ((XafLayoutControl)View.Control); layoutControl.OptionsCustomizationForm.ShowLayoutTreeView = false; //layoutControl.ShowCustomization += (s, e) => { // ((CustomizationForm)layoutControl.CustomizationForm).layoutControl1.BeginUpdate(); // var items = ((CustomizationForm)layoutControl.CustomizationForm).hiddenItemsGroup.Items; // items.RemoveAt(items.Count - 1); // items.RemoveAt(items.Count - 1); // ((CustomizationForm)layoutControl.CustomizationForm).layoutControl1.EndUpdate(); //}; } } }
    Visual Basic
    Option Infer On Imports DevExpress.ExpressApp Imports DevExpress.ExpressApp.Win.Layout Imports DevExpress.ExpressApp.Win.SystemModule Imports DevExpress.XtraLayout.Customization Namespace YourSolutionName.Module.Win Public Class MyWinLayoutManagerController Inherits ViewController(Of DashboardView) Public Sub New() Me.TargetViewId = "TestDashboard" End Sub Protected Overrides Sub OnActivated() MyBase.OnActivated() Frame.GetController(Of DashboardWinLayoutManagerController)().Active("T900193") = False End Sub Protected Overrides Sub OnDeactivated() Frame.GetController(Of DashboardWinLayoutManagerController)().Active.RemoveItem("T900193") MyBase.OnDeactivated() End Sub Protected Overrides Sub OnViewControlsCreated() MyBase.OnViewControlsCreated() Dim layoutControl = (CType(View.Control, XafLayoutControl)) layoutControl.OptionsCustomizationForm.ShowLayoutTreeView = False End Sub End Class End Namespace

    Pivot Chart Module (Analysis)

    C#
    using DevExpress.ExpressApp.PivotChart.Win; namespace MainDemo.Win.Controllers { public class MyAnalysisColumnChooserController : AnalysisColumnChooserController { protected override void OnActivated() { } } }

    Common

    This customization task is quite advanced and we do not have ready documentation for it. For further customizations in this regard, at least please research the XAF source code in the following files:

    • …\DevExpress.ExpressApp.Win\SystemModule\WinLayoutManagerController.cs
    • …\DevExpress.ExpressApp.Win\SystemModule\ColumnChooserControllerBase.cs
    • …\DevExpress.ExpressApp.Win\SystemModule\GridEditorColumnChooserController.cs
    • …DevExpress.ExpressApp.Win\SystemModule\DashboardWinLayoutManagerController.cs

    You may also find tips in the following KB article helpful when you face similar advanced UI customization tasks related to XAF or DevExpress controls: https://www.devexpress.com/products/net/application_framework/xaf-considerations-for-newcomers.xml.

    Search keywords

    customize layout, column chooser, customization window, form, hide, field list, GridControl, LayoutControl, field selector

      Show previous comments (4)

        I think you might want to change:

        C#
        protected virtual GridListEditorColumnChooserExtender CreateColumnChooserExtenderCore()

        to

        C#
        protected override GridListEditorColumnChooserExtender CreateColumnChooserExtenderCore()
        Dennis Garavsky (DevExpress) 8 years ago

          @Randy: I've corrected this typo, thanks.

            @Zotya Thanks for sharing. It works perfectly.

            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.