Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Diagram.Links.Add is not adding the link (Read 1893 times)
RogerC
YaBB Newbies
*
Offline


<Insert pithy saying here>

Posts: 2
Joined: Feb 12th, 2010
Diagram.Links.Add is not adding the link
Feb 12th, 2010 at 5:34pm
Print Post  
I have two classes that derive from DiagramLink: DiagramSequenceLink and DiagramActionLink. These classes represent workflow sequences and actions that I am modeling in my application. The DiagramSequenceLink contains a List<DiagramActionLink>. In the form's Shown event handler I am populating the Diagram from the workflow by creating and adding links to the Diagram.

Here is the problem. The second time I open the form only the DiagramSequenceLink objects are added to the diagram's Links collection. The DiagramActionLink objects don't get added. That is, the Links.Count is the same after the Links.Add() invocation as it is before. (The first time I open the form after launching my program, all of the links get added to the Diagram's Links collection just fine.) The result is that on the second opening of the form, the sequence links are visible but the action links are not, even though all the action links exist and have the Diagram as their Parent. I know they are there because when I select a sequence link, all of the anchor points of all its action links become visible (when you select a sequence link, my program selects all its action links so they can be manipulated as a group).

Here are snippets of the ctors:

private List<DiagramActionLink> actionlinks;
public DiagramSequenceLink(Diagram diagram, DiagramNode origin, DiagramNode destination, int anchor, WorkflowSequence workflowsequence)
: base(diagram, origin, destination)
{
.
.
.
diagram.Links.Add(this);
foreach (WorkflowAction action in workflowsequence.Actions)
{
actionlinks.Add(new DiagramActionLink(Parent, origin, destination, anchor, action));
}



public DiagramActionLink(Diagram diagram, DiagramNode origin, DiagramNode destination, int anchor, WorkflowAction workflowaction)
: base(diagram, origin, destination)
{
.
.
.
diagram.Links.Add(this); [color=Green]// This is the call that fails on the second opening of the form[/color]


The WorkflowSequence and WorkflowAction clases model the workflow in my application.

I am at a loss to explain why the DiagramActionLink objects can be added to the Diagram the first time the form is shown, but not after the form has been closed and then re-opened. Does anybody have any ideas?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Diagram.Links.Add is not adding the link
Reply #1 - Feb 12th, 2010 at 6:46pm
Print Post  
This happens if the origin and destination nodes are not in the diagram - could you verify that?
  
Back to top
 
IP Logged
 
RogerC
YaBB Newbies
*
Offline


<Insert pithy saying here>

Posts: 2
Joined: Feb 12th, 2010
Re: Diagram.Links.Add is not adding the link
Reply #2 - Feb 12th, 2010 at 8:29pm
Print Post  
Thanks for the tip. That was indeed the problem.

I was caching the origin and destination nodes using static variables in DiagramSequenceLink. Simply closing the form was not resetting these variables, so when I reopened the form they were still referring to nodes in the previous instance of the Diagram.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint