Ticket Q101774
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

How do I provide the capability to collapse or expand layout groups and persist their state?

How to implement expandable layout groups in Detail View layout (WinForms)

created 17 years ago

Hi
How do I implement Expandable Groups in the Layout Editor?
Regards
Andrew

Comments (1)
Dennis Garavsky (DevExpress) 17 years ago

    Hello,
    Sorry for the delay in processing your request. We're working on it, and will post our resolution as soon as it's ready.
    Thank you for your patience.
    Thanks,
    Dennis

    Answers approved by DevExpress Support

    created 17 years ago (modified 5 years ago)

    v19.2+
    With XAF v19.2, the new platform-agnostic options - IModelLayoutGroup.IsCollapsibleGroup and IModelLayoutGroup.IsGroupCollapsed - are available to control this behavior for both WinForms and ASP.NET apps. For more information on how it affects the former ASP.NET Application Model options, see this breaking change.

    For older versions or custom-tailored implementations when the standard solution is not suitable, consider the options from How do I provide the capability to collapse or expand layout groups and persist their state?


    Hi Andrew,

    In the simplest way, you can refer to the Access the Layout Control in Code help topic, to access the layout control and set the LayoutGroup.ExpandButtonVisible property for the required layout groups.
    This is the code of a controller I used to do this:

    C#
    using DevExpress.XtraLayout; namespace WinSolution.Module { public partial class MyLayoutViewController : ViewController { public MyLayoutViewController() { InitializeComponent(); RegisterActions(components); this.TargetObjectType = typeof(WinSolution.Module.MyPerson); this.TargetViewType = DevExpress.ExpressApp.ViewType.DetailView; } protected override void OnActivated() { base.OnActivated(); View.ControlsCreated += new EventHandler(View_ControlsCreated); } protected override void OnDeactivating() { base.OnDeactivating(); View.ControlsCreated -= new EventHandler(View_ControlsCreated); } void View_ControlsCreated(object sender, EventArgs e) { ((System.Windows.Forms.Control)View.Control).HandleCreated += new EventHandler(MyLayoutViewController_HandleCreated); } void MyLayoutViewController_HandleCreated(object sender, EventArgs e) { DevExpress.XtraLayout.LayoutControl layoutControl = ((DevExpress.XtraLayout.LayoutControl)((DetailView)View).Control); layoutControl.BeginUpdate(); try { foreach (object item in layoutControl.Items) { if (item is LayoutControlGroup) { ((LayoutControlGroup)item).ExpandButtonVisible = true; ((LayoutControlGroup)item).Expanded = true; ((LayoutControlGroup)item).ExpandButtonLocation = DevExpress.Utils.GroupElementLocation.AfterText; ((LayoutControlGroup)item).ExpandOnDoubleClick = true; } } } finally { layoutControl.EndUpdate(); } } } }

    My sample project is also attached. Please let me know if this solution suits your needs. Otherwise, please describe your requirements in more detail.
    Thanks,
    Dennis

      Other Answers

      created 14 years ago (modified 8 years ago)

      Hello,
      The following code can be used to do the same customization:

      C#
      using System; using DevExpress.XtraLayout; using DevExpress.ExpressApp; using System.Collections.Generic; using DevExpress.ExpressApp.Editors; using DevExpress.ExpressApp.Win.Layout; namespace MainDemo.Module.Win { public class Q101774 : ViewController<DetailView> { private ISupportAppearanceCustomization layoutManager; protected override void OnActivated() { base.OnActivated(); layoutManager = (ISupportAppearanceCustomization)View.LayoutManager; layoutManager.CustomizeAppearance += new EventHandler<CustomizeAppearanceEventArgs>(layoutManager_CustomizeAppearance); } private void layoutManager_CustomizeAppearance(object sender, CustomizeAppearanceEventArgs e) { LayoutControlGroup lg = ((WinLayoutItemAppearanceAdapter)e.Item).Item as LayoutControlGroup; if (lg != null) { lg.ExpandButtonVisible = true; lg.Expanded = true; lg.ExpandButtonLocation = DevExpress.Utils.GroupElementLocation.BeforeText; lg.ExpandOnDoubleClick = true; } } protected override void OnDeactivated() { layoutManager.CustomizeAppearance -= new EventHandler<CustomizeAppearanceEventArgs>(layoutManager_CustomizeAppearance); base.OnDeactivated(); } } }

      Attached is also a small video. It is also possible to extend the application model to save the expandable state.
      Thanks,
      Dennis

        Show previous comments (15)

          FYI - I tried both methods but the original method that loops through layoutgroups after the handlecreated event has much higher performance when rendering the detailview than using the CustomizeAppearance event. Cut my view load times in half or more.

          Dennis Garavsky (DevExpress) 11 years ago

            Thanks for your feedback, Chad

            Dennis Garavsky (DevExpress) 8 years ago

              I've attached a complete WinForms sample to the How do I provide the capability to collapse or expand layout groups and persist their state? ticket (see its WinForms section for the main implementation steps). I hope you find this information helpful.

              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.