[Mono-winforms-list] Add missing Find Method to TreeNodeCollection.

Neil Cawse neilcawse at geotab.com
Mon Jun 4 16:47:28 EDT 2007


Adding some of the missing methods our application relies on.

Index: /home/neilcawse/mymono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNodeCollection.cs
===================================================================
--- /home/neilcawse/mymono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNodeCollection.cs   (revision 78512)
+++ /home/neilcawse/mymono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNodeCollection.cs   (working copy)
@@ -25,6 +25,7 @@

 using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.ComponentModel;
 using System.Globalization;

@@ -434,7 +435,33 @@
                      nodes = nn;
               }

+#if NET_2_0
+              public TreeNode[] Find (string key, bool searchAllChildren) {
+                     List<TreeNode> results = new List<TreeNode>(0);
+                     Find (key, searchAllChildren, this, results);
+                     return results.ToArray();
+              }

+              private static void Find (string key, bool searchAllChildren, TreeNodeCollection nodes, List<TreeNode> results) {
+                     for (int i = 0; i < nodes.Count; i++) {
+                            TreeNode thisNode = nodes[i];
+                            if (string.Compare(thisNode.Name, key, true, CultureInfo.InvariantCulture) == 0) {
+                                   results.Add(thisNode);
+                            }
+                     }
+                     // Need to match the Microsoft order.
+                     if (searchAllChildren) {
+                            for (int i = 0; i < nodes.Count; i++) {
+                                   TreeNodeCollection childNodes = nodes[i].Nodes;
+                                   if (childNodes.Count > 0) {
+                                          Find(key, searchAllChildren, childNodes, results);
+                                   }
+                            }
+                     }
+              }
+#endif
+
+
               internal class TreeNodeEnumerator : IEnumerator {

                      private TreeNodeCollection collection;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-winforms-list/attachments/20070604/29876f24/attachment.html 


More information about the Mono-winforms-list mailing list