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

RadTreeNode Bounds property

2 Answers 77 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 19 May 2011, 08:52 AM
How can I get node bounding rectangle? There is no BoundingRectangle or Bounds or smth like this in RadTreeViewNode class.

2 Answers, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 20 May 2011, 10:13 AM
Wrote this method, is there an easier way?
       
public static Rectangle GetBounds(this RadTreeNode node)
{
    var nodeElement = node.TreeViewElement.ViewElement.Children
        .Cast<TreeNodeElement>()
        .FirstOrDefault(c => c.Data == node);
    if (nodeElement != null)
    {
        return nodeElement.BoundingRectangle;
    }
    else
    {
        int y = 0;
 
        RadTreeNode radTreeNode = node.TreeView.Nodes[0];
        if (radTreeNode == null)
        {
            throw new InvalidOperationException();
        }
        while (radTreeNode != node)
        {
            y += radTreeNode.ActualSize.Height;
            radTreeNode = radTreeNode.NextVisibleNode;
        }
        int itemHeight = radTreeNode.ActualSize.Height;
        var offset = node.TreeView.VScrollBar.Value;
        Rectangle bounds = new Rectangle(0, y - offset, node.TreeViewElement.Bounds.Width, itemHeight);
        return bounds;
    }
}



0
Jack
Telerik team
answered on 25 May 2011, 05:30 AM
Hello Alex,

RadTreeView uses layered architecture and RadTreeNode is just a logical object. The user interfaces uses virtualization and creates visual elements only for the nodes that are currently visible on screen. This improves the performance and and lowers the memory usage. Only the visual element - TreeNodeElement has a BoundingRectangle property. Yes, your solution will do the job. However, please elaborate a bit more and describe what exactly you want to achieve. This will help me to understand the issue and find the best option.

I look forward to your reply.
 
Regards,
Jack
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
Treeview
Asked by
Alex
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Jack
Telerik team
Share this question
or