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

[Solved] Setting visible=false can display incorrectly

0 Answers 115 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Darren Hall
Top achievements
Rank 1
Darren Hall asked on 06 Mar 2008, 12:56 PM

I have a treeview that shows nodes according to a users role.  if the user is not in the correct role I set visible = false on the node they should not see.  However if a node has several children and all children are set to visible = false, the actual rendered HTML still includes an empty <UL> where they would have been.  This causes a gap in the display.

I have come up with a workaround for anyone experiencing the same problem. You need to hook the treeview pre render as follows;

    protected void RadTreeView1_PreRender(object sender, EventArgs e)  
    {  
        // Note that although we set nodes that should not be displayed to visible = false 
        // Telerik still displays the <UL> for an empty section, we have to actually remove the nodes   
        // from the collection in order to display correctly.  
        // We use GetAllNodes for this as it returns every node in the tree and we count backwards  
        // so as not to upset the collection when items are removed.  
        for (int i = ((RadTreeView)sender).GetAllNodes().Count - 1; i >= 0 ; i--)  
        {  
            if (((RadTreeView)sender).GetAllNodes()[i].Visible == false)  
            {  
                ((RadTreeView)sender).GetAllNodes()[i].Remove();  
            }  
        }  
    } 

This removes the nodes from the collection and displays correctly.

Darren

No answers yet. Maybe you can help?

Tags
TreeView
Asked by
Darren Hall
Top achievements
Rank 1
Share this question
or