|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
TreeView duplicating nodes and also blowing up IEI've got a control that inherits TreeView and has some methods that firstly create a TreeNode then does some recursive procedure to add all the children from a database of a sort. Then once this is complete I clear the nodes, then add the TreeNode so it should be the only root node. The only problem is that for some very VERY strange reason there are two root nodes, with duplicate child nodes. This is very bizare as this.Nodes.Count returns 1 and base.Nodes.Count also returns 1, so there SHOULD be 1 root node but there are two. Also, I created another TreeView inherited control that would act as the base for this other TreeView which does all the painting by me, so that I can have different colors for highlighting and some other things and to make it double buffered and not flicker like mad but when I use this control as the base instead of the .NET one when I do this.Nodes.Add it basically blows the control up in Internet Explorer... So basically the TreeView is driving me slightly nuts, either I can have a TreeView with duplicate nodes that flickers when it updates the nodes, else I can have one thats flicker free and nice but only works when I add the nodes in edit mode, if I try adding them in code it kills Internet Explorer... any ideas? I'm already invoking back on the UI thread if it's needed to add the root node, so I know the problems not that... Some code:
TreeNode rootNode = new TreeNode(); FormatNode(ref rootNode, service); // this passes a service class and root and formats it text and color from the service classes details rootNode = AddChildren(rootNode); // add its children with recursive procedure... base.Nodes.Clear(); if (this.InvokeRequired == true) this.Invoke(new UpdateRootHandler(AddRoot), rootNode);//this.Nodes.Add(rootNode); else this.Nodes.Add(rootNode); ----------------------------------------------------------------------------------- private void AddRoot(TreeNode node) { this.Nodes.Add(node); } ----------------------------------------------------------------------------------- private TreeNode AddChildren(TreeNode node) { if (node == null) { Trace.WriteLine("AddChildren method has been passed a null node"); return node; } Service parentService = (Service)node.Tag; if (parentService == null) { Trace.WriteLine("AddChildren method has been passed a null service instance"); return node; } // Retrieve list of child services // & check the results returned are valid ArrayList children = parentService.Children; if (children == null || children.Count == 0) { Trace.WriteLine("Service: " + parentService.Name + " has no children."); return node; } // Increment each child service adding // them one by one to the hierarchy foreach (Service childService in children) { TreeNode childNode = null; childNode = new TreeNode(); FormatNode(ref childNode, childService); node.Nodes.Add(childNode); // Recursively add a child's children AddChildren(childNode); } return node; } These issue's are starting to drive me slightly mad, I can't understand
why either of these problems are occurring... according to the nodes collection there IS only one root, I really can't understand why two are being displayed, it really is rather strange... and why the other is blowing up I really don't know... I've spent ages debugging with traces and attaching to Internet Explorer's process... |
|||||||||||||||||||||||