Ticket Q307329
Visible to All Users

How to hide the toolbar of a nested list view

created 14 years ago

Hello,
I created the following controller to hide the toolbar of a nested listview :

C#
public partial class SuppressionToolbarVueLignesController : ViewController { #region Constructeurs public SuppressionToolbarVueLignesController() { InitializeComponent(); RegisterActions(components); } #endregion #region Méthodes /// <summary> /// Cache la toolbar /// </summary> /// <param name="template">Le template contenant la list view</param> private void CacheToolbar(NestedFrameTemplate template) { foreach (Bar bar in template.BarManager.Bars) { if (bar.BarName != "ListView Toolbar") continue; bar.Visible = false; return; } } #endregion private void SuppressionToolbarVueLignesController_ViewControlsCreated(object sender, EventArgs e) { CacheToolbar(Frame.Template as NestedFrameTemplate); } }

The code is correctly called, but the toolbar is not hidden.
What do I do wrong here,
Many thanks,
Julien

Answers approved by DevExpress Support

created 14 years ago (modified 2 years ago)

Hello Julien,

A nested View's menu belongs to its Frame Template. Customize this Template in code to hide or show its toolbar: Template Customization.
The best way to do this is to cast Frame.Template to the ISupportActionsToolbarVisibility interface and call the SetVisible method:

C#
using DevExpress.ExpressApp; using DevExpress.ExpressApp.Templates; public class MyHideToolbarController : ViewController { public MyHideToolbarController() { TargetViewNesting = Nesting.Nested; } protected override void OnActivated() { base.OnActivated(); if(Frame.Template == null) { Frame.TemplateChanged += Frame_TemplateChanged; } else { CustomizeTemplate(); } } private void Frame_TemplateChanged(object sender, EventArgs e) { CustomizeTemplate(); } private void CustomizeTemplate() { ISupportActionsToolbarVisibility template = Frame.Template as ISupportActionsToolbarVisibility; if(template != null) { template.SetVisible(false); } } protected override void OnDeactivated() { base.OnDeactivated(); Frame.TemplateChanged -= Frame_TemplateChanged; } }

Older versions:
Use the ISupportActionsToolbarVisibility.ShowActionsToolbar property:

C#
public class SuppressToolBarController : ViewController { protected override void OnActivated() { base.OnActivated(); View.ControlsCreated += new EventHandler(View_ControlsCreated); } void View_ControlsCreated(object sender, EventArgs e) { View.ControlsCreated -= new EventHandler(View_ControlsCreated); if(Frame != null && Frame.Template is ISupportActionsToolbarVisibility) { ((ISupportActionsToolbarVisibility)(Frame.Template)).ShowActionsToolbar = false; } } public SuppressToolBarController() { TargetViewId = "MyObject_ListView"; } }

Thanks,
Roman P

    Show previous comments (2)

      Hello Michael,
      via the CustomizeTemplate event, one can hide toolbars from all views generated between the Activated and the Deactivated-event of the view who initiates the hiding. In my case, I have to hide the toolbar from a view being displayed within a dashboard, for the other views, the toolbar should still be visible. How can this be achieved?
      Thank you,
      Markus

      DevExpress Support Team 12 years ago

        @Markus: You can specify whether a toolbar should be shown for a nested view within a dashboard by setting the IModelDashboardViewItem.ActionsToolbarVisibility property of the corresponding dashboard view item model.

          Apostolis - it's really cool that there's a implementation of that and I don't need to write it againt.
          Thanx once more :)

          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.