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.

Removing all the nodes on a layer from the model

Thread ID:

Created:

Updated:

Platform:

Replies:

70863 Jan 4,2008 03:47 PM Oct 5,2010 07:07 AM Windows Forms 2
loading
Tags: Diagram
Michael Jones
Asked On January 4, 2008 03:47 PM

How do you remove all the nodes from a layer - deleting the nodes from the diagram.

I tried this, but it has no effect:

for (int i = DiagramCanvas.Model.Layers[myLayerName].Nodes.Count - 1; i > 0; i--)
DiagramCanvas.Model.Layers[myLayerName].Nodes.Remove(DiagramCanvas.Model.Layers[myLayerName].Nodes[i]);

I have also tried removing directrly from the model using:

DiagramCanvas.Model.Nodes.Remove(DiagramCanvas.Model.Layers[myLayerName].Nodes[i])



Sri Rajan [Syncfusion]
Replied On January 5, 2008 12:09 AM

Hi Michael ,

If your intention is to remove all the nodes from the layer then you can use Model.RemoveChild() method. Please refer to the following code snippet.

[C#]

foreach (INode node in this.layer1.Nodes)
{
Node objnode = node as Node;
this.diagram1.Model.RemoveChild(objnode);
this.diagram1.Update();
}

Please refer the below sample to remove all the node from the diagram.

http://websamples.syncfusion.com/samples/Diagram.Windows/F70863/main.htm

In this sample you can remove the nodes in the layer by clicking on File-> RemoveNodes menuitem.

Please let me know if you have any questions.

Regards,
Srirajan


Witold Slirz
Replied On October 5, 2010 07:07 AM

It does not work.
If you use code like


foreach (Node node in _activeDiagram.Model.Layers[0].Nodes)
{
node.EditStyle.AllowDelete = true;
_activeDiagram.Model.RemoveChild(node);
}

Exception "collection was modified" occurs after one iteration.

How to delete all nodes from a layer?



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.

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.

;