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.

Testing to see if a connection between two nodes exists

Thread ID:

Created:

Updated:

Platform:

Replies:

107516 Mar 5,2013 05:46 PM Mar 6,2013 04:42 AM Windows Forms 1
loading
Tags: Diagram
Wayne Massey
Asked On March 5, 2013 05:46 PM

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?

Amsath Ali M [Syncfusion]
Replied On March 6, 2013 04:42 AM

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


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.

;