We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

TreeView add nodes by name

Thread ID:





21459 Nov 10,2004 05:22 PM Nov 15,2004 04:44 PM Windows Forms 3
Tags: Tools
Asked On November 10, 2004 05:22 PM

Hi, I am trying to add nodes to a Treeview control. The basic syntax is TreeNodeAdv nod = new TreeNodeAdv(NodText); tv.Nodes.Add(nod); and to add a node to the existing node you can use TreeNodeAdv nod2 = new TreeNodeAdv(NodText); nod.Nodes.Add(nod2); My question is, how do I add the second node to the first node based on the node name instead of the object itelf. Basically I know what the text is on the node that I what to add a node to, but I do not have the object reference. I can do this with a loop such as foreach (TreeNodeAdv tn in tv.Nodes) { if (tn.Text == tempText) { tn.Nodes.Add(nod2); break; } } this works, but this is obviously very inefficient, is there a better way

Administrator [Syncfusion]
Replied On November 11, 2004 06:14 PM

Hi Rich, I am afraid, in the current implementation of TreeViewAdv control we do not have any built-in API to retrieve a TreeNodeAdv based on its Text. So the above approach is the only way of achieving this functionality presently. However, we could consider this as a feature request for a future release of Essential Suite. Please provide us the following information : 1. Should the Text based search be conducted over multiple levels ? 2. How should it handle a scenario which contains TreeNodeAdvs with same Text (but at different levels) ? Thanks for your interest in Syncfusion products. Regards, Guru Patwal Syncfusion, Inc.

Replied On November 11, 2004 08:57 PM

I think the best idea for doing the search is to ask for a starting node, and simply search the children for that node.

Administrator [Syncfusion]
Replied On November 15, 2004 04:44 PM

Hi Rich, Thanks for the update. In that case, will the above mentioned simple linear search technique meet your requirements (since we already know the parent TreeNodeAdv object)? If not, do you wish to use some other search technique ? Please let me know. We appreciate your cooperation. Regards, Guru Patwal Syncfusion, Inc.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.