private void RefreshNode(TreeNode thisRoot) { //Debug.WriteLine("In RefreshNode: Node = " & thisRoot.Tag.path & " -- " & thisRoot.Tag.displayname) if (!(thisRoot.Nodes.Count == 1 && thisRoot.Nodes[0].Text.Equals(" : "))) { CShItem thisItem = thisRoot.Tag as CShItem; if (thisItem.RefreshDirectories()) //RefreshDirectories True = the contained list of Directories has changed { List <CShItem> curDirs = thisItem.GetDirectories(false); //suppress 2nd refresh ArrayList delNodes = new ArrayList(); TreeNode node; foreach (TreeNode tempLoopVar_node in thisRoot.Nodes) //this is the old node contents { node = tempLoopVar_node; int i; for (i = 0; i <= curDirs.Count - 1; i++) { if (((CShItem)(curDirs[i])).Equals(node.Tag)) { curDirs.RemoveAt(i); //found it, don't compare again goto NXTOLD; } } //fall thru = node no longer here delNodes.Add(node); NXTOLD: 1.GetHashCode(); //nop } if (delNodes.Count + curDirs.Count > 0) //had changes { try { tv1.BeginUpdate(); foreach (TreeNode tempLoopVar_node in delNodes) //dir not here anymore, delete node { node = tempLoopVar_node; thisRoot.Nodes.Remove(node); } //any CShItems remaining in curDirs is a new dir under thisRoot CShItem csi; foreach (CShItem tempLoopVar_csi in curDirs) { csi = tempLoopVar_csi; if (!(csi.IsHidden && !m_showHiddenFolders)) { thisRoot.Nodes.Add(MakeNode(csi)); } } //we only need to resort if we added //sort is based on CShItem in .Tag if (curDirs.Count > 0) { TreeNode[] tmpA = new TreeNode[thisRoot.Nodes.Count]; thisRoot.Nodes.CopyTo(tmpA, 0); Array.Sort(tmpA, new ExpTreeLib.CShItem.TagComparer()); thisRoot.Nodes.Clear(); thisRoot.Nodes.AddRange(tmpA); } } catch (Exception ex) { Debug.WriteLine("Error in RefreshNode -- " + ex.ToString() + "\r\n" + ex.StackTrace); } finally { tv1.EndUpdate(); } } } } //Debug.WriteLine("Exited RefreshNode") }