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. Image for the cookie policy date

Removing all the nodes on a layer from the model

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])



2 Replies

SR Sri Rajan Syncfusion Team January 5, 2008 05:09 AM UTC

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



WS Witold Slirz October 5, 2010 11:07 AM UTC

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?



Loader.
Live Chat Icon For mobile
Up arrow icon