Missing properties of web treeview

2 posts, 0 answers
  1. Jean-Louis GOBERT
    Jean-Louis GOBERT avatar
    52 posts
    Member since:
    May 2007

    Posted 06 May 2010 Link to this post

    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
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 11 May 2010 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top