/// <summary> /// Check if parentNode already contain childNodeText /// WARNING : SEARCH CASE INSENSITIVE /// </summary> /// <param name="parentNode"></param> /// <param name="childNodeText"></param> /// <returns></returns> public static bool IsChildNodeExist(TreeNode parentNode, string childNodeText) { TreeNode oNodeFound = Win32TreeViewUtility.GetChildNode(parentNode, childNodeText); if (oNodeFound == null) { return(false); } return(true); }
/// <summary> /// Remove a treenode & its childs using file path /// </summary> /// <param name="sourceTreeView"></param> /// <param name="path"></param> public static void RemoveTreeNodeFromPath(TreeView sourceTreeView, string path, bool removeParentIfEmpty) { TreeNode oNodeToManage = Win32TreeViewUtility.GetNodeFromPath(sourceTreeView, path); if (oNodeToManage != null) { TreeNode oParent = oNodeToManage.Parent; oNodeToManage.Remove(); if (removeParentIfEmpty) { RemoveEmptyParents(oParent); } } }
public static TreeNode AddTreeNodeFromRegistryPath(TreeView sourceTreeView, string path) { if (path == null) { throw new NolmeArgumentNullException(); } if (sourceTreeView == null) { throw new NolmeArgumentNullException(); } string szDriveLetter; string [] aszPath = DirectoryUtility.SplitRelativePath(path); TreeNode oNode, oOutNode; //bool bResult; oNode = null; if (aszPath.Length != 0) { // Add first element szDriveLetter = aszPath[0]; oOutNode = Win32TreeViewUtility.GetChildNode(sourceTreeView, szDriveLetter); if (oOutNode == null) { oOutNode = sourceTreeView.Nodes.Add(szDriveLetter); } oNode = oOutNode; // Add other elemetns for (int i = 1; i < aszPath.Length; i++) { oOutNode = Win32TreeViewUtility.GetChildNode(oNode, aszPath[i]); if (oOutNode == null) { oOutNode = oNode.Nodes.Add(aszPath[i]); } // Switch parent node oNode = oOutNode; } } return(oNode); }