TreeViewExtensions.cs (768B)
1 using System; 2 using System.Windows.Forms; 3 4 namespace LanTool.Classes 5 { 6 /// <summary> 7 /// ExtensionsMethods für das WinForms-TreeView-Control 8 /// </summary> 9 public static class TreeViewExtensions 10 { 11 /// <summary> 12 /// Einen einzelnen TreeNode in der kompletten Hierarchie suchen 13 /// </summary> 14 /// <param name="treeView">TreeView, dass durchsucht werden soll</param> 15 /// <param name="path">Name/Pfad des gesuchten TreeNode</param> 16 /// <returns>den TreeNode, wenn einer gefunden wird, ansonsten null</returns> 17 public static TreeNode FindSingleNode( this TreeView treeView, String path ) 18 { 19 if ( treeView == null ) 20 { 21 return null; 22 } 23 24 TreeNode[] tn = treeView.Nodes.Find( path, true ); 25 return tn.Length > 0 ? tn[0] : null; 26 } 27 } 28 }