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

[Solved] FindNodeByText

5 Answers 422 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Robert O'Dell
Top achievements
Rank 1
Robert O'Dell asked on 25 Dec 2007, 11:40 PM
Hi,
I'm biting the bullet and converting an application that is not due to be released for a few months to Prometheus.  An issue I've run across involves FindNodeByText.  It appears I can use the statement mytree.FindNodeByText("some text"), but can't use it on subtrees For example, the following form I used a number of times in the application.  nodeLevel1.Nodes.FindNodeByText("some text").  While I can convert the application to use FindNodeByText at the tree level, the use of subtree searching was useful as there was the potential for nodes by the same name in different sublevels (the same would true of FindNodeByValue).  Have I missed something in converting that would make the construct I was using - usable?
Thanks,
Bob O'Dell

5 Answers, 1 is accepted

Sort by
0
NEX
Top achievements
Rank 1
answered on 26 Dec 2007, 04:36 AM
Nope you haven't I was just about to report the same issue.  Actually all of the Find methods no longer exist on the ChildNodes level.  They must have forgotten to put them back or something because I can't imagine why they would remove them.
0
NEX
Top achievements
Rank 1
answered on 26 Dec 2007, 01:22 PM
Well...since we don't know how long Telerik will take to fix this little problem.  I just decided to create my own search methods.  This also gives you the ability to change it to search for just about any additional properties in the tree if you wish ;) 

        public enum FindByField { Value, Text, LongDesc }

        public static RadTreeNode FindbyValue(RadTreeNode root, string value)
        {
            return TreeSearch(root, value, true, FindByField.Value);
        }

        public static RadTreeNode FindbyText(RadTreeNode root, string value)
        {
            return TreeSearch(root, value, true, FindByField.Text);
        }

        public static RadTreeNode FindbyDesc(RadTreeNode root, string value)
        {
            return TreeSearch(root, value, true, FindByField.LongDesc);
        }

        /// <summary>
        /// Given a root node searches ALL children nodes for a specific value.
        /// </summary>
        /// <param name="root">node to start searching from</param>
        /// <param name="value">string value to search for</param>
        /// <param name="recursive">Recursive search: false to search ONLY immediate child nodes</param>
        /// <param name="field">Node field to search in</param>
        /// <returns></returns>
        public static RadTreeNode TreeSearch(RadTreeNode root, string value, bool recursive, FindByField field)
        {
            if (root != null)
            {
                string nvalue = "";
               
                switch (field)
                {
                    case FindByField.Value:
                        nvalue = root.Value;
                        break;
                    case FindByField.Text:
                        nvalue = root.Text;
                        break;
                    case FindByField.LongDesc:
                        nvalue = root.LongDesc;
                        break;
                }
               
                if (nvalue == value)
                    return root;
                else if (root.Nodes != null)
                {
                    RadTreeNode node;
                    foreach (RadTreeNode childnode in root.Nodes)
                    {
                        if (!recursive)
                        {
                            switch (field)
                            {
                                case FindByField.Value:
                                    nvalue = childnode.Value;
                                    break;
                                case FindByField.Text:
                                    nvalue = childnode.Text;
                                    break;
                                case FindByField.LongDesc:
                                    nvalue = childnode.LongDesc;
                                    break;
                            }
               
                            if (nvalue == value)
                                return childnode;
                        }
                        else
                        {
                            node = TreeSearch(childnode, value, recursive, field);
                            if (node != null)
                                return node;
                        }
                    }
                }
            }

            return null;
        }

0
Atanas Korchev
Telerik team
answered on 27 Dec 2007, 11:32 AM
Hello guys,

The FindNodeByText method of the RadTreeNodeCollection will be implemented for the service pack release.

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Robert O'Dell
Top achievements
Rank 1
answered on 03 Jan 2008, 01:23 AM
Since I have to the iterim release, I attempted to use both prometheus and radcontrols in the same page with the hope of
What I attempted to do in the interim was use the RadControl treeview in place of the prometheus one.  Which doesn't seem to work.  Apparently the two assemblies conflict since I get a message the two assemblies namespaces are not unambigious.  I could change the code to make them unambigious, but that's a lot of change.  I have set that page back to all Radcontrol - leaving the rest of the application in prometheus. 

So the question - when do you think the interim release will be?  I would really like time to test the application before its release but all in prometheus

Thanks
0
Warren
Top achievements
Rank 1
answered on 03 Jan 2008, 01:36 AM
Robert,

If you're going to use RadTreeView classic on the same page as RadControls Prometheus, you will need to do a search & replace, "RadTree" with "Telerik.WebControls.RadTree".  That will resolve the ambiguity.  Of course, you will also need to use distinct namespace prefixes in ASPX and ASCX files for the RadTreeView.net2 and Telerik.Web.UI assemblies.


If you are upgrading to .NET Framework 3.5, you could also implement your custom search routines using extension methods instead of using static methods.  Much cleaner that way...

Tags
TreeView
Asked by
Robert O'Dell
Top achievements
Rank 1
Answers by
NEX
Top achievements
Rank 1
Atanas Korchev
Telerik team
Robert O'Dell
Top achievements
Rank 1
Warren
Top achievements
Rank 1
Share this question
or