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
close icon

Testing to see if a connection between two nodes exists

Hi,
 
I am drawing a diagram based on content from a database table. As part of the process, I create several rectangles and then link them together if they are related. In this application, It is valid for their to be multiple links between two of the same rectangles.
 
Since there is multiple links, I end up creating the same lineconnector between two rectangles multiple times. As I have a label associated with the lineconnector, the label text merges together.
 
What I would like to do is If I have a Node, test to see if there is already a connection to a second node. If so, update the existing connection. If not, create a new connection.
 
I am new here but looking through the help docs, I am not sure how to test this. Is this possible?

1 Reply

AA Amsath Ali M Syncfusion Team March 6, 2013 09:42 AM UTC

Hi Wayne,

 

Thanks for using Syncfusion products.

 

We suggest you to use the Diagram.Model.EventSink’s ‘ConnectionChanged’ event to check whether the connections have been present the nodes or not. Please refer the below code snippet to achieve your requirement.

Here is the code:

[C#]

void EventSink_ConnectionsChanged(CollectionExEventArgs evtArgs)

        {

            if (evtArgs.ChangeType == CollectionExChangeType.Insert)

            {

                if (evtArgs.Element is EndPoint)

                {

                    ConnectorBase conn = ((EndPoint)evtArgs.Element).Container as ConnectorBase;

                    if (conn != null)

                    {

                        if (conn.FromNode != null && conn.ToNode != null)

                        {

                            Node toNode = conn.ToNode as Node;

                            foreach (ConnectorBase nodeConns in conn.ToNode.Edges)

                            {

                                if (((nodeConns.FromNode == conn.FromNode && nodeConns.ToNode == conn.ToNode) ||

                                    (nodeConns.FromNode == conn.ToNode && nodeConns.ToNode == conn.FromNode)) && conn != nodeConns)

                                {

                                    evtArgs.Cancel = true;                                   

                                    diagram1.Model.RemoveChild(conn);

                                    break;

                                }

                            }

                        }

                    }

                }

            }

        }

 

Here is the sample:

http://www.syncfusion.com/downloads/Support/DirectTrac/105295/F107516-1585009003.zip

 

Please let us know if you have any queries.

 

Regards,

Amsath Ali. M


Loader.
Live Chat Icon For mobile
Up arrow icon