automatically delete child nodes
I need a code example to automatically delete child nodes of a parent node as shown in the image
Greetings, Thanks
Edward Montiel
imagen_ba72ca98.rar
Greetings, Thanks
Edward Montiel
imagen_ba72ca98.rar
SIGN IN To post a reply.
4 Replies
PM
Pandi Murugan A
Syncfusion Team
June 3, 2011 04:53 AM UTC
Hi Edward,
Thanks for using Syncfusion products.
Here is the code snippet to achieve your requirement.
Please try this and let me know if this is helps.
Regards,
Pandi Murugan A
Thanks for using Syncfusion products.
Here is the code snippet to achieve your requirement.
[C#]
//Add NodeCollectionChanged event
diagram1.Model.EventSink.NodeCollectionChanged += new CollectionExEventHandler(EventSink_NodeCollectionChanged);
void EventSink_NodeCollectionChanged(CollectionExEventArgs evtArgs)
{
//Check whether the selected node is deleted or not
if (evtArgs.ChangeType == CollectionExChangeType.Remove)
{
if (evtArgs.Elements != null)
{
foreach (Node node in evtArgs.Elements)
DeleteChild(node);//Delete child and inner level child
}
}
}
void DeleteChild(Node parent)
{
NodeCollection nodes = new NodeCollection();
foreach (ConnectorBase link in parent.EdgesLeaving)
{
if (link.ToNode != null)
{
DeleteChild((Node)link.ToNode);
nodes.Add((Node)link.ToNode);//Add the child to the collection for deleting
}
nodes.Add(link);//Add the link from parent to the collection for deleting
}
foreach (Node node in nodes)
{
diagram1.Model.RemoveChild(node);//remove the child from model
}
}
Please try this and let me know if this is helps.
Regards,
Pandi Murugan A
ED
ed
June 5, 2011 04:14 AM UTC
perfect just what I needed thanks for your help
Greetings
Edward Montiel
Greetings
Edward Montiel
ED
ed
June 5, 2011 08:42 PM UTC
Now I have this question, how to have the user can not remove the nodes with the Delete key, is there any way to remove that function
Greetings
Edward Montiel
Greetings
Edward Montiel
AA
Amsath Ali M
Syncfusion Team
June 6, 2011 11:52 AM UTC
Hi Edward,
Thanks for the update.
We suggest you to use the below code snippet to restrict the user from deleting the node through ‘Delete’ Key.
[C#]:
diagram1.KeyDown += new KeyEventHandler(diagram1_KeyDown);
void diagram1_KeyDown(object sender, KeyEventArgs e)
{
//Check whether the delete key is pressed or not
if (e.KeyCode == Keys.Delete)
{
e.SuppressKeyPress = true;
}
}
Please try this and let us know if this helps.
Regards,
Amsath Ali.M
Thanks for the update.
We suggest you to use the below code snippet to restrict the user from deleting the node through ‘Delete’ Key.
[C#]:
diagram1.KeyDown += new KeyEventHandler(diagram1_KeyDown);
void diagram1_KeyDown(object sender, KeyEventArgs e)
{
//Check whether the delete key is pressed or not
if (e.KeyCode == Keys.Delete)
{
e.SuppressKeyPress = true;
}
}
Please try this and let us know if this helps.
Regards,
Amsath Ali.M
SIGN IN To post a reply.
- 4 Replies
- 3 Participants
-
ED ed
- Jun 1, 2011 02:49 PM UTC
- Jun 6, 2011 11:52 AM UTC