Feature request: FindNodebyKey

8 posts, 0 answers
  1. Marek
    Marek avatar
    48 posts
    Member since:
    Aug 2005

    Posted 02 May 2007 Link to this post

    Hi
    It would be useful to be able to add nodes to the tree, specifying a key and then to be able to locate that node with a call along the lines of:

    RadTreeNode node = radTreeView.GetNodeByKey(key);

    Best regards

    Marek
  2. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 02 May 2007 Link to this post

    Hello Marek,

    Thank you for the proposal. The feature will be present in the SP1 of RadControls for WinForms in a couple of weeks.
    If you have more ideas do not hesitate to share them with us.






    Greetings,
    Ray
    the telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ian
    Ian avatar
    6 posts
    Member since:
    Oct 2007

    Posted 28 Feb 2008 Link to this post

    Hi
    Has this feature been implemented yet? I can only see GetNodeByPath

    Ian
  5. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 29 Feb 2008 Link to this post

    Hello Ian,

    Thank you for writing.

    This method was indeed implemented, but shortly after that it as replaced by the Find method of RadTreeNode Collection. This was done in order to provide better compatibility with the Windows Forms TreeView control.

    Also, functionality allowing to execute arbitrary actions on a subtree of nodes in the form of commands has been added (the ExecuteBatchCommand and ExecuteScalarCommand static methods of RadTreeView). These methods can be used to search a subtree of nodes by executing a custom command for every node in that subtree.

    This functionality is still relatively new, so any feedback will be greatly appreciated.

    If you have any additional questions, please contact me.

    Hope that helps.

    Greetings,
    Jordan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Ian
    Ian avatar
    6 posts
    Member since:
    Oct 2007

    Posted 02 Mar 2008 Link to this post

    Thanks for that

    It would helpful if you could give a usage example on how to find a node by key. I am using the tag property of the nodes to store either a DataRow value or an array and I see the parameter for the value to search in Find is a string.

    Also the two commands you describe look interesting but also would like an example of their use

    Either VB or C#

    Many thanks

    Ian
  7. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 04 Mar 2008 Link to this post

    Hello Ian,

    Thank you for writing back. Here are the details you requested:

    1. We should set the Name property of RadTreeNode as it is used for comparison in the Find method:
       
          private void SetNodesNames()     
              {     
                  Stack<RadTreeNode> stack = new Stack<RadTreeNode>();     
                  RadTreeNode node = null;     
                  int depth = 1;     
                     
                  int i;     
                  for (i = this.radTreeView1.Nodes.Count - 1; i > -1; i--)     
                  {     
                      node = this.radTreeView1.Nodes[i];     
                      if (node.Visible)     
                      {     
                          stack.Push(node);     
                      }     
                  }     
          
                  Stack<RadTreeNode> parentStack = new Stack<RadTreeNode>();     
                  while (stack.Count > 0)     
                  {     
                      node = stack.Pop();     
                      while (parentStack.Count > 0 && parentStack.Peek() != node.Parent)     
                      {     
                          parentStack.Pop();     
                          depth--;     
                      }     
          
                      node.Name = node.Text;     
                       
                   
                      if ((node.Nodes.Count > 0))     
                      {     
                          for (i = node.Nodes.Count - 1; i > -1; i--)     
                          {     
                              stack.Push(node.Nodes[i]);       
                          }     
                          parentStack.Push(node);     
                          depth++;     
                      }     
                  }     
              }    
       

       
    2. Then you can use the following syntax to search for a node:
       
          RadTreeNode[] nodes = this.radTreeView1.Nodes.Find("Search Folders", true);

      The "Search Folders" string represents the name of a node to search for. We set "true" to allow searching in the subtrees.  

    The ExecuteBatchCommand is used as follows:

        Telerik.WinControls.UI.
    RadTreeView.ExecuteBatchCommand(this.radTreeView1.Nodes, -1, RadTreeNode.ExpandCollapseCommand, true);
     
    There are a few default commands in RadTreeNode which you can use. If you would like you could create your own commands deriving the CommandBase class.

    If you have any other questions please write us back.
     

    Best wishes,
    Boyko Markov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. Husam Al Madain
    Husam  Al Madain avatar
    1 posts
    Member since:
    Mar 2010

    Posted 17 Mar 2011 Link to this post

    the function find is not exist in q1 2011
    radTreeView1.Nodes.Find(
    "Search Folders"true); 

    how can i get the node by name
  9. Svett
    Admin
    Svett avatar
    728 posts

    Posted 18 Mar 2011 Link to this post

    Hi Husam Al Madain,

    There is a breaking change regarding this method. You can use the following code snippet to find a node by key:

    private List<RadTreeNode> Find(string key, bool searchAllChildren, RadTreeNodeCollection treeNodeCollectionToLookIn)
    {
        List<RadTreeNode> list = new List<RadTreeNode>();
     
        if ((treeNodeCollectionToLookIn == null) || (list == null))
        {
            return null;
        }
        for (int i = 0; i < treeNodeCollectionToLookIn.Count; i++)
        {
            if (treeNodeCollectionToLookIn[i] != null)
            {
                if (String.Compare(treeNodeCollectionToLookIn[i].Text, key, true) == 0)
                {
                    list.Add(treeNodeCollectionToLookIn[i]);
                }
                if (searchAllChildren && (treeNodeCollectionToLookIn[i].Nodes.Count > 0))
                {
                    list.AddRange(this.Find(key, searchAllChildren, treeNodeCollectionToLookIn[i].Nodes));
                }
            }
        }
        return list;
    }

    All the best,
    Svett
    the Telerik team
Back to Top
UI for WinForms is Visual Studio 2017 Ready