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

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

3 Answers 135 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Amit
Top achievements
Rank 1
Amit asked on 19 Oct 2011, 09:01 AM
Hi All,

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

Thanks,
Amit Choudhary

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 19 Oct 2011, 11:33 AM
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.
0
Amit
Top achievements
Rank 1
answered on 19 Oct 2011, 11:39 AM
Hi Princy,

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

Thanks,
Amit Choudhary
0
Accepted
Veli
Telerik team
answered on 21 Oct 2011, 10:37 AM
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
Tags
TreeList
Asked by
Amit
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Amit
Top achievements
Rank 1
Veli
Telerik team
Share this question
or