We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

automatically delete child nodes

Thread ID:

Created:

Updated:

Platform:

Replies:

99640 Jun 1,2011 10:49 AM Jun 6,2011 07:52 AM Windows Forms 4
loading
Tags: Diagram
ed
Asked On June 1, 2011 10:49 AM

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

Pandi Murugan A [Syncfusion]
Replied On June 3, 2011 12:53 AM

Hi Edward,

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
Replied On June 5, 2011 12:14 AM

perfect just what I needed thanks for your help


Greetings

Edward Montiel


ed
Replied On June 5, 2011 04:42 PM

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


Amsath Ali M [Syncfusion]
Replied On June 6, 2011 07:52 AM

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




CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;