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

Missing properties of web treeview

1 Answer 66 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Jean-Louis GOBERT
Top achievements
Rank 1
Jean-Louis GOBERT asked on 06 May 2010, 12:54 PM
Hi ! I hope this post will have its place here...

I realised a tree view in asp.net, and now I need to do the same for a winform... the matter is that there aren't the same properties.

For example I am using these methods in the asp version :
private void Filter() 
        { 
            try 
            { 
                LoadAllNodes(); 
                if (accountTextBox.Text.TrimEnd().Equals("*") || string.IsNullOrEmpty(accountTextBox.Text.TrimEnd())) 
                    return
 
                //Get all nodes matching the filter 
                List<RadTreeNode> matchingNodes = new List<RadTreeNode>(); 
                IList<RadTreeNode> nodesToFilter = ((List<RadTreeNode>)radTreeView.GetAllNodes()).FindAll(delegate(RadTreeNode rdTNode) { return rdTNode.Tag.Equals("Account"); }); 
                for (int i = 0; i < nodesToFilter.Count; i++) 
                { 
                    if (nodesToFilter[i].Text.StartsWith(accountTextBox.Text.TrimEnd(), StringComparison.OrdinalIgnoreCase)) 
                        matchingNodes.Add(nodesToFilter[i]); 
                } 
 
                IList<RadTreeNode> allNodes = radTreeView.GetAllNodes(); 
                for (int i = 0; i < allNodes.Count; i++) 
                { 
                    if (IsToFilter(allNodes[i], matchingNodes)) 
                        allNodes[i].Remove(); 
                } 
            } 
            catch (Exception ex) 
            { 
                throw ex; 
            } 
        } 

private bool IsToFilter(RadTreeNode radTreeNode, List<RadTreeNode> matchingNodes) 
        { 
            if (radTreeNode.Text.StartsWith(accountTextBox.Text.TrimEnd(), StringComparison.OrdinalIgnoreCase)) 
                return false
 
            foreach (RadTreeNode item in matchingNodes) 
            { 
                if (radTreeNode.IsAncestorOf(item)) 
                    return false
            } 
 
            return true
        } 

But for winform version there is no method "GetAllNodes()" for RadTreeView, and I have the same problem with "IsAncestorOf".

Could you help me and explain me which property/metho I can use without changing all my code ?

Thanks a lot !

Jean

1 Answer, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 11 May 2010, 12:30 PM
Hi Jean-Louis GOBERT,

Thank you for writing.

RadTreeView for Windows Forms is different from the ASP.NET RadTreeView. The API's are not identical and some methods and properties will certainly differ. The two methods that you need can be trivially implemented via recursion. The first method should traverse the tree view node hierarchy and add all nodes to a list and then return it. The second should simply go up the parent chain of a node and compare by reference the node provided as an argument with the current node in the chain (The IsAncestorOf() method).
If you are using C# 3.0 or newer, you can use the extension methods feature which will allow you to simply write the methods and your existing code will just work. Please consider the following code snippet:

public static class RadTreeViewExtensions
{
    public static List<RadTreeNode> GetAllNodes(this RadTreeView tv)
    {
        List<RadTreeNode> result = new List<RadTreeNode>();
 
        GetAllNodes(tv.Nodes, result);
 
        return result;
    }
 
    public static void GetAllNodes(RadTreeNodeCollection nodes, List<RadTreeNode> result)
    {
        foreach (RadTreeNode current in nodes)
        {
            result.Add(current);
            GetAllNodes(current.Nodes, result);
        }
    }
 
    public static bool IsAncestorOf(this RadTreeNode node, RadTreeNode nodeToCheck)
    {
        RadTreeNode parent = node.Parent;
 
        while (parent != null)
        {
            if (parent == nodeToCheck)
            {
                return true;
            }
 
            parent = parent.Parent;
        }
 
        return false;
    }
}

Write again if you have other questions.

 

Sincerely yours,
Victor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Treeview
Asked by
Jean-Louis GOBERT
Top achievements
Rank 1
Answers by
Victor
Telerik team
Share this question
or