By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,210 Members | 1,405 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,210 IT Pros & Developers. It's quick & easy.

how is TreeNodeCollection.Find implemented?

P: n/a
Hi,

If you look at TreeNodeCollection.Find Method, you'll see:

Finds the tree nodes with specified key, optionally searching subnodes.

public TreeNode[] Find (
string key,
bool searchAllChildren
)

My question is - how is the find impelmented? is there a hash that
holds the keys or does the Find method really go over each node and
search for the key?

Thanks
Engel

Mar 29 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

en**********@gmail.com wrote:
Hi,

If you look at TreeNodeCollection.Find Method, you'll see:

Finds the tree nodes with specified key, optionally searching subnodes.

public TreeNode[] Find (
string key,
bool searchAllChildren
)

My question is - how is the find impelmented?
For all such questions, you can discover the answer yourself using Lutz
Roeder's Reflector (google result 1 for 'reflector'), which is
basically a .NET disassembler: point it at System.Windows.Forms.dll
and...
is there a hash that
holds the keys or does the Find method really go over each node and
search for the key?


public TreeNode[] Find(string key, bool searchAllChildren)
{
ArrayList list1 = this.FindInternal(key, searchAllChildren, this,
new ArrayList());
TreeNode[] nodeArray1 = new TreeNode[list1.Count];
list1.CopyTo(nodeArray1, 0);
return nodeArray1;
}

private ArrayList FindInternal(string key, bool searchAllChildren,
TreeNodeCollection treeNodeCollectionToLookIn, ArrayList
foundTreeNodes)
{
if ((treeNodeCollectionToLookIn == null) || (foundTreeNodes ==
null))
{
return null;
}
for (int num1 = 0; num1 < treeNodeCollectionToLookIn.Count;
num1++)
{
if ((treeNodeCollectionToLookIn[num1] != null) &&
WindowsFormsUtils.SafeCompareStrings(treeNodeColle ctionToLookIn[num1].Name,
key, true))
{
foundTreeNodes.Add(treeNodeCollectionToLookIn[num1]);
}
}
if (searchAllChildren)
{
for (int num2 = 0; num2 < treeNodeCollectionToLookIn.Count;
num2++)
{
if (((treeNodeCollectionToLookIn[num2] != null) &&
(treeNodeCollectionToLookIn[num2].Nodes != null)) &&
(treeNodeCollectionToLookIn[num2].Nodes.Count > 0))
{
foundTreeNodes = this.FindInternal(key,
searchAllChildren, treeNodeCollectionToLookIn[num2].Nodes,
foundTreeNodes);
}
}
}
return foundTreeNodes;
}

--
Larry Lard
Replies to group please

Mar 29 '06 #2

P: n/a
Thanks!

Mar 29 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.