diff --git a/PROMS/VEPROMS.CSLA.Library/VEObjects/VETreeNode.cs b/PROMS/VEPROMS.CSLA.Library/VEObjects/VETreeNode.cs index ea735b34..320da092 100644 --- a/PROMS/VEPROMS.CSLA.Library/VEObjects/VETreeNode.cs +++ b/PROMS/VEPROMS.CSLA.Library/VEObjects/VETreeNode.cs @@ -338,19 +338,61 @@ namespace VEPROMS.CSLA.Library //if (Nodes.Count > 1) // Console.WriteLine("{0}, {1}",Nodes[0], Nodes[1]); - if (!myItemInfo.HasChildren && !(Nodes[0] is VETreeNode)) + if (!myItemInfo.HasChildren && Nodes.Count>0 && !(Nodes[0] is VETreeNode)) Nodes.Clear(); } void myItemInfo_NewChild(object sender, ItemInfoInsertEventArgs args) { + if (args.ItemInserted.NextItem != null) // insert before + { + int nextItemID = args.ItemInserted.NextItem.ItemID; + VETreeNode nextNode = FindChildOrGrandChild(nextItemID); + nextNode.myItemInfo_NewSiblingBefore(sender, args); + return; + } + if (args.ItemInserted.MyPrevious != null) // insert after + { + int prevItemID = args.ItemInserted.MyPrevious.ItemID; + VETreeNode prevNode = FindChildOrGrandChild(prevItemID); + prevNode.myItemInfo_NewSiblingAfter(sender, args); + return; + } bool isExpanded = IsExpanded; // Restore the tree as it currently is expanded. Collapse(); Nodes.Clear(); _ChildrenLoaded = false; ResetNode("Dummy myItemInfo_NewChild"); - //if (isExpanded) Expand(); - Collapse(); + ItemInfo item = VEObject as ItemInfo; + if (isExpanded && item != null && item.MyContent.ContentPartCount >1) // || args.ItemInserted.NextItem != null || args.ItemInserted.MyPrevious != null)) + Expand(); + else + Collapse(); + } + private VETreeNode FindChildOrGrandChild(int itemID) + { + foreach (TreeNode childNode in Nodes) + { + VETreeNode child = childNode as VETreeNode; + if (child != null) + { + ItemInfo item = child.VEObject as ItemInfo; + if (item != null && item.ItemID == itemID) + return child; + } + } + foreach (TreeNode childNode in Nodes) + { + VETreeNode child = childNode as VETreeNode; + if (child != null && child.VEObject is PartInfo) + foreach (VETreeNode grandchild in child.Nodes) + { + ItemInfo item = grandchild.VEObject as ItemInfo; + if (item != null && item.ItemID == itemID) + return grandchild; + } + } + return null; } void myItemInfo_NewSiblingBefore(object sender, ItemInfoInsertEventArgs args) {