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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do I enable the single link between the nodes?

Platform: WinForms |
Control: Diagram |
Published Date: April 30, 2011 |
Last Revised Date: June 3, 2019

How do I enable the single link between the nodes?

We can eliminate creating two links for the same two symbols by checking the link nodes FromNode, ToNode properties. While creating lines we have to check the end points, if its end points is already exists with the symbols then we have to remove the link. While creating links we can get the link endpoints using ConnectionsChanged event.

C#

//Adding ConnectionChanged event
((DocumentEventSink)model1.EventSink).ConnectionsChanged += new CollectionExEventHandler(MainForm_ConnectionsChanged);
 //Event
void MainForm_ConnectionsChanged(CollectionExEventArgs evtArgs)
{
if (evtArgs.ChangeType == CollectionExChangeType.Insert)
{
foreach (Node n1 in this.diagram1.Model.Nodes)
{
Line tl = n1 as Line;
if (n1 is Line)
{
Line lc1 = n1 as Line;
foreach (Node n in this.diagram1.Model.Nodes)
{
if (n is Line && n != n1)
{
Line lc = n as Line;
if (((lc1.FromNode == lc.FromNode) && (lc1.ToNode == lc.ToNode)) || ((lc1.ToNode == lc.FromNode) && (lc1.FromNode == lc.ToNode)))
{
this.diagram1.Model.RemoveChild(lc1);
MessageBox.Show("Aleardy link has created for the Symbols");
}
}
}
}
}
}
}
 

 

VB

'Adding ConnectionChanged event
AddHandler (CType(model1.EventSink, DocumentEventSink)).ConnectionsChanged, AddressOf MainForm_ConnectionsChanged
 'Event
void MainForm_ConnectionsChanged(CollectionExEventArgs evtArgs)
If evtArgs.ChangeType = CollectionExChangeType.Insert Then
For Each n1 As Node In Me.diagram1.Model.Nodes
Dim tl As Line = TryCast(n1, Line)
If TypeOf n1 Is Line Then
Dim lc1 As Line = TryCast(n1, Line)
For Each n As Node In Me.diagram1.Model.Nodes
If TypeOf n Is Line AndAlso Not n Is n1 Then
Dim lc As Line = TryCast(n, Line)
If ((lc1.FromNode = lc.FromNode) AndAlso (lc1.ToNode = lc.ToNode)) OrElse ((lc1.ToNode = lc.FromNode) AndAlso (lc1.FromNode = lc.ToNode)) Then
Me.diagram1.Model.RemoveChild(lc1)
MessageBox.Show("Aleardy link has created for the Symbols")
End If
End If
Next n
End If
Next n1
End If

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

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