Hi,
I have these three lines of code:
//previously remove afterSelect event
1: if (utvProjectView.ActiveNode.Parent.Nodes.Count == 1)2: utvProjectView.ActiveNode.Parent.Remove();3: else4: utvProjectView.ActiveNode.Remove();5: utvProjectView.AfterSelect += new AfterNodeSelectEventHandler(utvProjectView_AfterSelect);6: utvProjectView.ActiveNode.Selected = true;
I put a stopper on line 6. When I hold my mouse over ActiveNode, it says null. If I wait 2 seconds, hold my mouse over ActiveNode again, then suddenly it shows it being as the first node in the tree. What gives? And I don't have the event hooked twice (afterSelect) so the 2 second pause is not because some other piece of code is executing.
Thanks.
Sorry, what is not clear about the above code? It is checking to see if the parent node of the node I am removing count = 1, if it is then remove the parent since it has no children, otherwise just remove the child node.
When removing a node from your tree control via code, the tree automatically activates another node, usually the parent of the child being removed. When stepping through this code, after the node is removed and the control goes to the next node when i mouse over ActiveNode intellisense shows null, then a second later shows whatever node it is. Because the code executes faster then a second the client pops and error that the active node is null. We use your tree's a lot, we have 100 of them in our application and we need to understand WHY this is.
What I find fustrating on these boards is that I know AHEAD of time that the first reply to my question is going to be something completely off base with what I ask. I spend more time thinking of the right way to ask question then I do anything else to avoid this and hopefully find a resolution to my issue in 2 days, not 4.
I'm not sure what the code you posted is supposed to do, but if you remove a node you can't select it because it no longer belongs to the control.
The way the ActiveNode property getter works is, when there is no value explicitly assigned to it, it returns the first visible node if there is one or more visible nodes, and null if there are no nodes.