How to remove Plus(Add) button from Child Nodes?

4 posts, 1 answers
  1. Amit
    Amit avatar
    88 posts
    Member since:
    Sep 2010

    Posted 19 Oct 2011 Link to this post

    Hi All,

    I want to remove the plus(Add) button from all the child nodes. How can i achieve it?

    Thanks,
    Amit Choudhary
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Oct 2011 Link to this post

    Hello Amit,

    You can try the following CSS to remove Expand and Collapse buttons.
    CSS:
    <style type="text/css">
    .RadTreeList_Default .rtlExpand
    {
      background-image:none !important;
    }
    .RadTreeList_Default .rtlCollapse
    {
      background-image:none !important;
    }
     </style>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Amit
    Amit avatar
    88 posts
    Member since:
    Sep 2010

    Posted 19 Oct 2011 Link to this post

    Hi Princy,

    I want to remove the Add button for all child nodes as shown in attached image.

    Thanks,
    Amit Choudhary
  5. Answer
    Veli
    Admin
    Veli avatar
    2002 posts

    Posted 21 Oct 2011 Link to this post

    Hello Amit,

    You can use the ItemDataBound event in RadTreeList to do that.

    If you only have 2 levels of hierarchy and you want to remove the add new button from the child items, you can use the following snippet:

    protected void RadTreeList1_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
    {
        if (e.Item is TreeListDataItem)
        {
            var dataItem = (TreeListDataItem)e.Item;
            if (dataItem.HierarchyIndex.NestedLevel != 0)
            {
                //specify your edit column's UniqueName here
                dataItem["EditCommandColumn"].Controls[0].Visible = false;
            }
        }
    }

    Alternatively, if you have more than 2 levels of hierarchy and want to hide the add button for leaf nodes only, you can take a different approach:

    protected void RadTreeList1_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
    {
        if (e.Item is TreeListDataItem)
        {
            var dataItem = (TreeListDataItem)e.Item;
            bool isLeaf = true;
     
            //search for an expand/collapse button in the item
            foreach (TableCell cell in dataItem.Cells)
            {
                if (cell.Controls.Count > 0 && cell.Controls[0].ID == "ExpandCollapseButton")
                {
                    isLeaf = false;
                    break;
                }
            }
     
            if (isLeaf)
            {
                dataItem["EditCommandColumn"].Controls[0].Visible = false;
            }
        }
    }

    The second approach searches for the expand/collapse button in the data item. If none is found, the item is a "loaf node", meaning it does not have any child items and should have its add button hidden.

    Veli
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top