This is a migrated thread and some comments may be shown as answers.

Restrict hiding of item

2 Answers 24 Views
LayoutControl
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 05 Dec 2018, 04:00 AM

Is there a way restrict the user from being able to hide certain control items?

I want to allow our users to be able to customise the layout to large extent but there are a couple of items that should always be on screen. I've browsed the documentation but I couldn't see anything that would help.

2 Answers, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 05 Dec 2018, 07:37 AM
Hi Rob,

Thank you for writing.

Currently, the RadLayoutControl misses the API to allow you to cancel hiding certain layout control items. I have logged a feature request on our feedback portal, here: ADD. RadLayoutControl - expose API specifying whether items can be hidden or not. I have also updated your Telerik points. Currently, the desired behavior can be achieved with a custom control and some reflection: 
public class CustomRadLayoutControl : RadLayoutControl
{
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadLayoutControl).FullName;
        }
    }
 
    protected override void InitializeDropDownMenu()
    {
        FieldInfo hideMenuItemFi = typeof(RadLayoutControl).GetField("hideMenuItem", BindingFlags.Instance | BindingFlags.NonPublic);
        RadMenuItem hideMenuItem = hideMenuItemFi.GetValue(this) as RadMenuItem;
 
        if (hideMenuItem == null)
        {
            hideMenuItemFi.SetValue(this, new RadMenuItem(LayoutControlLocalizationProvider.CurrentProvider.GetLocalizedString(LayoutControlStringId.ContextMenuCustomize)));
            hideMenuItem = hideMenuItemFi.GetValue(this) as RadMenuItem;
        }
 
        hideMenuItem.Click += customizeItem_Click;
 
        RadDropDownMenu menu = typeof(RadLayoutControl).GetField("dropDownMenu", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this) as RadDropDownMenu;
        menu.Items.Add(hideMenuItem);
    }
 
    private void customizeItem_Click(object sender, EventArgs e)
    {
        if (this.AllowCustomize)
        {
            this.ShowCustomizeMenuDialog();
        }
    }
 
    private void ShowCustomizeMenuDialog()
    {
        if (this.CustomizeDialog.Visible)
        {
            return;
        }
 
        this.ShowCustomDragOverlay();
        this.CustomizeDialog.Owner = this.FindForm();
        ThemeResolutionService.ApplyThemeToControlTree(this.CustomizeDialog, this.ThemeName);
 
        if (this.CustomizeDialog.Location == Point.Empty)
        {
            this.CustomizeDialog.Location = GetInitialCustomizeDialogLocation();
        }
 
        this.CustomizeDialog.Show();
        this.CustomizeDialog.RightToLeft = this.RightToLeft;
    }
 
    private void ShowCustomDragOverlay()
    {
        FieldInfo dragOverlayFi = typeof(RadLayoutControl).GetField("dragOverlay", BindingFlags.Instance | BindingFlags.NonPublic);
        LayoutControlDraggableOverlay dragOverlay = dragOverlayFi.GetValue(this) as LayoutControlDraggableOverlay;
 
        if (dragOverlay == null)
        {
            dragOverlayFi.SetValue(this, new CustomLayoutControlDraggableOverlay(this));
            dragOverlay = dragOverlayFi.GetValue(this) as LayoutControlDraggableOverlay;
        }
 
        dragOverlay.ThemeName = this.ThemeName;
        dragOverlay.UpdatePreview();
 
        dragOverlay.Dock = DockStyle.Fill;
        ((RadLayoutControlControlCollection)this.Controls).AddInternal(dragOverlay);
        dragOverlay.Visible = true;
        dragOverlay.BringToFront();
        this.PerformLayout();
        this.Refresh();
    }
 
}
 
public class CustomLayoutControlDraggableOverlay : LayoutControlDraggableOverlay
{
    private RadMenuItem hideMenuItem;
 
 
    public CustomLayoutControlDraggableOverlay(RadLayoutControl owner)
        : base(owner)
    {
        RadDropDownMenu contextMenu = typeof(LayoutControlDraggableOverlay).GetField("contextMenu", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this) as RadDropDownMenu;
        contextMenu.Items.Clear();
 
        this.hideMenuItem = new RadMenuItem(LayoutControlLocalizationProvider.CurrentProvider.GetLocalizedString(LayoutControlStringId.ContextMenuHideItem));
        this.hideMenuItem.Text = LayoutControlLocalizationProvider.CurrentProvider.GetLocalizedString(LayoutControlStringId.ContextMenuHideItem);
        this.hideMenuItem.Click += hideMenuItem_Click;
        contextMenu.Items.Add(hideMenuItem);
        contextMenu.DropDownOpening += ContextMenu_DropDownOpening;
    }
 
    private void ContextMenu_DropDownOpening(object sender, CancelEventArgs e)
    {
        if (this.SelectedItems.Count == 1 && this.SelectedItems[0].Name == "layoutControlItem4")
        {
            e.Cancel = true;
        }
    }
 
    private void hideMenuItem_Click(object sender, EventArgs e)
    {
        foreach (DraggableLayoutControlItem item in this.SelectedItems)
        {
            if (item.Name == "layoutControlItem4")
            {
                continue;
            }
 
            this.Owner.HideItem(item.AssociatedItem);
        }
 
        this.UpdatePreview();
    }
}

I hope this will help. Let me know if you have other questions.

Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More. Rob
0
Rob
Top achievements
Rank 1
answered on 05 Dec 2018, 10:33 PM
Thanks Hristo, this worked great.
Tags
LayoutControl
Asked by
Rob
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Rob
Top achievements
Rank 1
Share this question
or