How to get the newly added and removed items in the WinForms Diagram?
In the WinForms Diagram Control, you can be notified of new elements added to the Diagram or existing elements removed from the Diagram using the NodeCollectionChanged event. This event allows you to handle changes in the diagram’s elements dynamically.
Code snippet:
//Event for node/connectors adding and removing.
diagram1.EventSink.NodeCollectionChanged += EventSink_NodeCollectionChanged;
//Event to notify when node and connector are added or removed
private void EventSink_NodeCollectionChanged(Syncfusion.Windows.Forms.Diagram.CollectionExEventArgs evtArgs)
{
// This will help to find the element that is added to the diagram.
if (evtArgs.ChangeType == CollectionExChangeType.Insert)
{
// You can get the element from the evtArgs.Element
if (evtArgs.Element is Rectangle)
{
Rectangle rect = (Rectangle)evtArgs.Element;
}
}
// This will help to find the element that is removed from the diagram.
else if (evtArgs.ChangeType == CollectionExChangeType.Remove)
{
// You can get the element from the evtArgs.Element
if (evtArgs.Element is Rectangle)
{
Rectangle rect = (Rectangle)evtArgs.Element;
}
}
}
Conclusion:
I hope you enjoyed learning about how to get the newly added and removed items in the WinForms Diagram.
You can refer to our WinForms Diagram feature tour page to learn about its other groundbreaking feature representations. You can also explore our WinForms Diagram documentation to understand how to create and manipulate data.
You can check out our components from the License and Downloads page for current customers. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.
Please let us know in the comments section below if you have any queries or require clarifications. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!