I can’t get the parent node of “current_node” deleted from my Tree. Here is what I am trying:
I am developing in C# .NET for VSTO
TreeGridNode current_node = myTreeGrid.CurrentNode;
TreeGridNode parent_node = myTreeGrid.CurrentNode.Parent;
// this works
myTreeGrid.Nodes.Remove(current_node);
if (parent_node.Nodes.Count == 0) {
// it never gets here, it doesn't detect that the lats child was just removed above
myTreeGrid.Nodes.Remove(parent_node);
}
using this custom structure
http://blogs.msdn.com/b/markrideout/archive/2006/01/08/510700.aspx
I believe that your problem here is that you are trying to remove
current_nodefrommyTreeGridand notcurrent_node‘s parent.myTreeGrid.Nodesdoes not contain a reference tocurrent_node, so callingmyTreeGrid.Nodes.Remove(current_node)essentially does nothing.Since nothing is ever removed,
parent_node.Nodesstill contains the reference tocurrent_node. Try removingcurrent_nodedirectly fromparent_node.Nodesand your issue will probably be resolved:Change:
to