Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Delete all children when deleting a parent node (Read 1388 times)
newbieDraw
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 24
Joined: Dec 22nd, 2011
Delete all children when deleting a parent node
May 2nd, 2013 at 2:52pm
Print Post  
Hello Stoyo,

I have developed an application that lets users draw/import nodes from database in a tree format. Is it possible to do the following (without elaborate coding)?
1. to delete all the children node when a parent is deleted. I recently faced an issue where the nodes still existed (isolated) on the diagram, but were not visible.
2. To copy all children when a parent is copied (given that the tree is collapsed from the parent node, so only parent node is visible).

Thanks,

Parijat
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Delete all children when deleting a parent node
Reply #1 - May 2nd, 2013 at 8:15pm
Print Post  
Hi Parijat,

You should be able to implement it with some recursion.

1. Call the following method in response to your delete command from menus. To delete whole branch in response to del key, set DelKeyAction to None and handle KeyDown:Del yourself by calling the method on diagram.ActiveItem.

Code
Select All
void DeleteWithChildren(DiagramNode node)
{
	foreach (var link in node.OutgoingLinks.Clone())
		DeleteWithChildren(link.Destination);
	diagram.Items.Remove(node);
} 



2. Copying to clipboard works on currently selected items, so you will have to recursively select children before calling CopyToClipboard:

Code
Select All
void CopyWithChildren(DiagramNode node)
{
	SelectWithChildren(node);
	diagramView.CopyToClipboard(true);
	diagram.Selection.Change(node);
}

void SelectWithChildren(DiagramNode node)
{
	node.Selected = true;
	foreach (var link in node.OutgoingLinks)
	{
		link.Selected = true;
		SelectWithChildren(link.Destination);
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint