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

How can I disable insert on an item by item basis?

3 Answers 135 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 22 Mar 2011, 06:40 PM
Hello,

I'm using the automatically generated edit and insert controls for the RadTreeView and so far everything is working out fine, except that I'm stuck on one thing.

I would like to limit the number of nested inserts a user can do by disabling and hiding the insert on certain rows (which will be determined programatically in the ItemDataBound Event).

This is just a simple example of what I'd like to do.  Basically if the "level" of the item is 4, I would like to disable and hide the insert.

protected void ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
   {
       if (e.Item.ItemType == TreeListItemType.AlternatingItem || e.Item.ItemType == TreeListItemType.Item)
       {
           TreeListDataItem item = e.Item as TreeListDataItem;
           int level = (int)DataBinder.Eval(item.DataItem,"Level");
           if (level == 4)
           {
               item["InsertCommandColumn"].Enabled = false;
                
           }
             
       }
   }

The item["InsertCommandColumn"].Enabled kind of works, but it keeps the control visible and confusing for the end user.

If I hide the Cell entirely, all of the other cells shift over to fill the void.

Is there a more graceful way to disable an automatically generated insert button on a row by row basis?

3 Answers, 1 is accepted

Sort by
0
Accepted
Martin
Telerik team
answered on 25 Mar 2011, 04:20 PM
Hello David,

Instead of hiding the cell that holds the buttons you can hide the button(s). Since you want to hide the buttons on a nested level basis you can use the ItemCreated event like this:

protected void RadTreeList1_ItemCreated(object sender, Telerik.Web.UI.TreeListItemCreatedEventArgs e)
{
    if (e.Item.ItemType == TreeListItemType.AlternatingItem || e.Item.ItemType == TreeListItemType.Item)
    {
        TreeListDataItem item = e.Item as TreeListDataItem;
        int level = item.HierarchyIndex.NestedLevel;
        if (level == 0)
        {
            (item["MyEditCommandColumn"].FindControl("InsertButton_MyEditCommandColumn") as LinkButton).Visible = false;
        }
        if (level == 1)
        {
            (item["MyEditCommandColumn"].FindControl("EditButton_MyEditCommandColumn") as LinkButton).Visible = false;
        }
    }
}

I hope this helps.

Greetings,
Martin
the Telerik team
0
David
Top achievements
Rank 1
answered on 25 Mar 2011, 05:03 PM
Your example pointed me in the right direction, thanks!

0
David
Top achievements
Rank 1
answered on 25 Mar 2011, 05:53 PM
Quick follow up question to anyone needing this code.

I was losing my formatting when I opened a row for editing, so I had to also check the SelectedItem flag when determining if I should format the row.
Tags
TreeList
Asked by
David
Top achievements
Rank 1
Answers by
Martin
Telerik team
David
Top achievements
Rank 1
Share this question
or