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.
Syncfusion Feedback

How to validate links

Thread ID:

Created:

Updated:

Platform:

Replies:

36711 Nov 8,2005 02:30 PM UTC Nov 18,2005 01:32 AM UTC Windows Forms 2
loading
Tags: Diagram
Leo Rabinovich
Asked On November 8, 2005 02:30 PM UTC

Is there a way to validate/restrict connection between two ports based on the type value set up with the SetPropertyValue method? For instance I have two symbols with two ports, input and output, on each symbol. The only restriction is that output port on one symbol can be connected only to the input port of another symbol. I’ve tried to use ConnectionsChanging event, it raised twice, and if one connection is valid but another is not the link will still be created. Following is the code that I have. Thanks, Leo private void diagram1_Model_ConnectionsChanging(object sender, ConnectionCollectionEventArgs evtArgs) { if((evtArgs.ChangeType == CollectionExChangeType.Insert) && (evtArgs.Connection != null)) { Connection newconn = evtArgs.Connection; if(newconn.SourcePort is LinkPort) { Link link = (Link)((LinkPort)newconn.SourcePort).Container; string sourcePortType = null, targetPortType = null; foreach (Connection c in link.Connections) { if (c.SourcePort is CirclePort) { CirclePort cport = (CirclePort)c.SourcePort; sourcePortType = Convert.ToString(cport.GetPropertyValue("type")); } if (c.TargetPort is CirclePort) { CirclePort cport = (CirclePort)c.TargetPort; targetPortType = Convert.ToString(cport.GetPropertyValue("type")); } } if (sourcePortType != targetPortType)evtArgs.Cancel = true; } if(newconn.TargetPort is LinkTailPort) { Link link = (Link)((LinkTailPort)newconn.TargetPort).Container; string sourcePortType = null, targetPortType = null; foreach (Connection c in link.Connections) { if (c.SourcePort is CirclePort) { CirclePort cport = (CirclePort)c.SourcePort; sourcePortType = Convert.ToString(cport.GetPropertyValue("type")); } if (c.TargetPort is CirclePort) { CirclePort cport = (CirclePort)c.TargetPort; targetPortType = Convert.ToString(cport.GetPropertyValue("type")); } } if (sourcePortType != targetPortType) evtArgs.Cancel = true; } } }

Administrator [Syncfusion]
Replied On November 11, 2005 05:19 PM UTC

Hi Leo, The ConnectionsChanging/ConnectionsChangeComplete events will be fired twice when creating a link - once each for the connection at each end of the link. To determine the identity of the ports(and their host symbols) that the link is connecting to, you will have to handle the event when it generated the second time around, as the first occurence of the event will provide you with access to only the ports involved in the first connection. An easy way to determine whether the event is being fired for the first or second connection is by accessing the link, and examining whether the Link.FromNode and Link.ToNode properties are both valid. The following Essential Diagram KB article shows how to use the ConnectionsChangeComplete event to examine the symbols on either end of a link, and to remove the link if the connection is not required - http://www.syncfusion.com/support/kb/diagram/Default.aspx?ToDo=view&questId=34. I hope this helps. Thanks, Prakash Surendra Syncfusion Inc.,

Leo Rabinovich
Replied On November 18, 2005 01:32 AM UTC

Thanks Prakash for your reply. I''ll try your suggestion as soon as I get a chance.

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.

Warning Icon 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.Close Icon

;