Tree node fixes when deleting nodes

This commit is contained in:
2010-01-15 17:05:41 +00:00
parent 61c9d01516
commit cdf14f6328
5 changed files with 120 additions and 82 deletions

View File

@@ -1078,7 +1078,7 @@ namespace VEPROMS.CSLA.Library
string number = (MyContent.Type >= 20000 ? Ordinal.ToString() + "." : ((MyContent.Number ?? "") == "" ? MyContent.Text : MyContent.Number));
ItemInfo parent = this;
while (parent.MyPrevious != null) parent = parent.MyPrevious;
if (parent.ItemPartCount == 0)
if (parent.ItemPartCount <= 0 || parent.ItemParts.Count == 0)
return null;
else
{

View File

@@ -183,6 +183,20 @@ namespace VEPROMS.CSLA.Library
internal void OnDeleted(object sender)
{
if (Deleted != null) Deleted(sender);
if (MyParent != null) MyParent.OnChildrenDeleted(sender);
}
public event ItemInfoEvent ChildrenDeleted;
internal void OnChildrenDeleted(object sender)
{
if (_CacheByPrimaryKey.ContainsKey(ItemID.ToString()))
{
List<ItemInfo> itmlst = _CacheByPrimaryKey[ItemID.ToString()];
foreach (ItemInfo itm in itmlst)
if (itm.ChildrenDeleted != null)
{
itm.ChildrenDeleted(itm);
}
}
}
public event ItemInfoInsertEvent NewSiblingAfter;
internal void OnNewSiblingAfter(object sender, ItemInfoInsertEventArgs args)

View File

@@ -323,12 +323,24 @@ namespace VEPROMS.CSLA.Library
if (myItemInfo != null)
{
myItemInfo.Deleted += new ItemInfoEvent(myItemInfo_Deleted);
myItemInfo.ChildrenDeleted += new ItemInfoEvent(myItemInfo_ChildrenDeleted);
myItemInfo.MyContent.Changed += new ContentInfoEvent(MyContent_Changed);
myItemInfo.NewSiblingAfter += new ItemInfoInsertEvent(myItemInfo_NewSiblingAfter);
myItemInfo.NewSiblingBefore += new ItemInfoInsertEvent(myItemInfo_NewSiblingBefore);
myItemInfo.NewChild += new ItemInfoInsertEvent(myItemInfo_NewChild);
}
}
void myItemInfo_ChildrenDeleted(object sender)
{
//Console.WriteLine("Fix Children");
ItemInfo myItemInfo = VEObject as ItemInfo;
//if (Nodes.Count > 1)
// Console.WriteLine("{0}, {1}",Nodes[0], Nodes[1]);
if (!myItemInfo.HasChildren && !(Nodes[0] is VETreeNode))
Nodes.Clear();
}
void myItemInfo_NewChild(object sender, ItemInfoInsertEventArgs args)
{
bool isExpanded = IsExpanded;
@@ -337,7 +349,8 @@ namespace VEPROMS.CSLA.Library
Nodes.Clear();
_ChildrenLoaded = false;
ResetNode("Dummy myItemInfo_NewChild");
if (isExpanded) Expand();
//if (isExpanded) Expand();
Collapse();
}
void myItemInfo_NewSiblingBefore(object sender, ItemInfoInsertEventArgs args)
{