The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
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;
}
}
}
ADAdministrator Syncfusion Team 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.,
LRLeo RabinovichNovember 18, 2005 01:32 AM UTC
Thanks Prakash for your reply. I''ll try your suggestion as soon as I get a chance.