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