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

check connections

Hi

I'm working wiht Hierarchical Layout demo  How Can I check if two RoundRect Nodes are already connected to avoid calling again ConnectNodes if parentnode and childnode are already connected ?

Thanks,

Olivier

7 Replies

KR Kameshwaran R Syncfusion Team April 24, 2017 11:45 AM UTC

  
Hi Olivier, 
Please use node’s EdgesEntering and EdgesLeaving property to achieve your requirement and its used to get the number of connections connected with the node and number of connection leaving from node.  
Here is the code snippet. 
private void ConnectNodes(Node parentNode, Node childNode) 
{ 
            if ((parentNode != null && parentNode.EdgesEntering.Count < 1) && (childNode != null && childNode.EdgesLeaving.Count < 1)) 
            { 
                //..... 
            } 
} 
Regards, 
Kameshwaran R. 



OL Olivier April 24, 2017 12:32 PM UTC

Hi,

Thanks for your answer. As a parentnode can be connected to several childs, I can't use this solution. Parent A can be connected to child B and C, if A-C connection exists, I don't wand to call once again sonnectNodes(A,C). I was searching for a way fo get FromNode/ToNode information. I saw that I could check an event like connectionschanged but it does not seems very nice to add a connection to cancel it after. 

In other words, given two RoundRect nodes A and B, is it possible to get information "A is connected to B" ?

Olivier


NG Naganathan Ganesh Babu Syncfusion Team April 25, 2017 06:31 AM UTC

Hi Oliver, 
 
To achieve your requirement, we suggest you to use Node’s “EdgesLeaving” property to access the child from the parent. Please find the below code example and sample. 
 
Code example: 
 
[C#] 
 
void EventSink_ConnectionsChanged(CollectionExEventArgs evtArgs) 
{ 
if (evtArgs.ChangeType == CollectionExChangeType.Insert && evtArgs.Element is TailEndPoint) 
{ 
ConnectorBase connector = (evtArgs.Element as EndPoint).Container as ConnectorBase; 
if (connector != null) 
{ 
Node frmNode = connector.FromNode as Node; 
Node toNode = connector.ToNode as Node; 
if (frmNode != null) 
{ 
foreach (ConnectorBase con in frmNode.EdgesLeaving) 
{ 
if (con.ToNode == toNode) 
{ 
toNode.CentralPort.Disconnect(connector.HeadEndPoint); 
MessageBox.Show("Parent has already connected with this child"); 
} 
} 
} 
} 
} 
} 
 
Sample: 
 
 
Regards, 
 
Naganathan K G 
 
 



OL Olivier April 25, 2017 06:52 AM UTC

Hi,

Thanks for this answer. As explained previously, I saw that it was possible to use an insert connection event to remove it if a previous one was existing. But this implies to add a connection to remove it after, which is not very optimized.

I ask my question in an another way : Given a node found from it's name, how can I find it's parent ?

Thanks,

Olivier


NG Naganathan Ganesh Babu Syncfusion Team April 25, 2017 09:44 AM UTC

Hi Olivier, 
  
In our Diagram Control, the ConnectionChanging/ConnectionChanged events fired first time for the HeadEndPoint of the connector (while trying to connect the child) and next for the TailEndPoint of the connector (while trying to connect the parent). So, we can’t find the parent node of the current child and then can’t check the child node already connected with that parent node.  
 
So only we have provided the solution in previous, i.e. to check and disconnect the child node, after creating the connection if the parent node already connected with that node. 
 
However, we have modified the sample to check and prevent the connection creation if the child node’s “EdgesEntering” count is more than one. Please find the below modified sample and let us know if your requirement is achieved or not? 
 
Code example: 
 
[C#] 
 
private Node m_toNode; 
 
void EventSink_ConnectionsChanged(CollectionExEventArgs evtArgs) 
{ 
ConnectorBase connector = (evtArgs.Element as EndPoint).Container as ConnectorBase; 
if (evtArgs.ChangeType == CollectionExChangeType.Insert && evtArgs.Element is HeadEndPoint) 
{ 
Node toNode = connector.ToNode as Node; 
if (toNode.EdgesEntering.Count > 1) 
{ 
m_toNode = toNode; 
evtArgs.Cancel = true; 
} 
} 
if (evtArgs.ChangeType == CollectionExChangeType.Insert && evtArgs.Element is TailEndPoint) 
{ 
if (connector != null) 
{ 
Node frmNode = connector.FromNode as Node; 
if (frmNode != null) 
{ 
foreach (ConnectorBase con in frmNode.EdgesLeaving) 
{ 
if (con.ToNode == m_toNode) 
{ 
MessageBox.Show("Parent has already connected with this child"); 
} 
} 
}                    
m_toNode = null; 
} 
} 
} 
 
Modified Sample: 
 
 
Note: 
 
In above modified code is always disconnect the childnode if we trying to connect more than one connection.  
 
Regards, 
 
Naganathan K G 
 
  



OL Olivier April 25, 2017 02:38 PM UTC

Hi,

Yes, your solution might work but would not allow a child to have two parents. What surprises me the most is that it seams that there is no way to find the parent of a connected node ?

Olivier


NG Naganathan Ganesh Babu Syncfusion Team April 26, 2017 12:50 PM UTC

Hi Olivier, 
  
We have created a new incident for this query. Please log on to our support website to check for further updates. 
  
  
Regards, 
  
Naganathan K G 


Loader.
Live Chat Icon For mobile
Up arrow icon