Bonehead problem... links don't show


Apologies for the trivial nature of my problem… I’m sure I’m missing something simple.
I’m trying to create a view with two nodes (GoBasicNode) and a link (GoLink) between them. The nodes display properly, but I can’t get the link to show. I’m using the demo version of Express for .NET.
After creating the nodes, I create a port on each of them, create a new link, and set the FromPort and ToPort properties on the link. What else do I need to do to get the link to display?
Thanks for any help…


Are you adding the link to the document? I think, more specificially, you should add the link to the LinkLayer of the document. Then it’ll show up.


I tried the following:
1. myView.Document.Add(link);
2. myView.Document.LinksLayer.Add(link)
3. myView.CreateLink(port1, port2)
All with the same results… no link visible. I also set the pen and brush for the link, no joy there either. The code follows (from the ctor of the view)
_miisInstance = new CMIISInstance(“name”, “”);
this.Text = “test View”;
GoView myView = new GoView();
myView.Dock = DockStyle.Fill;
CMIISNode miisNode = new CMIISNode(_miisInstance);
miisNode.Location = new PointF(myView.Right/2, myView.Bottom/2);
double radAngle = 0;
double radIncr = (2*Math.PI)/_miisInstance.get_NMAs();
float scale = (Math.Min(myView.Right, myView.Bottom)/2) - Math.Max(miisNode.Width, miisNode.Height);
for(int i = 0; i < _miisInstance.get_NMAs(); i++)
CMANode maNode = new CMANode(_miisInstance.get_MAs());
maNode.Location = new PointF(miisNode.Location.X + (float)Math.Sin(radAngle)*scale, miisNode.Location.Y + (float)Math.Cos(radAngle)*scale);
maNode.Label.Editable = false; // second node is editable by clicking only
maNode.Brush = Brushes.Magenta;
GoPort port1 = maNode.CreatePort();
GoPort port2 = miisNode.CreatePort();
GoLink link = new GoLink();
link.FromPort = port1;
link.ToPort = port2;

radAngle += radIncr;


My only guess at this point would be to make sure that those ports that are getting created with calls to “CreatePort()” are actually getting added to their respective nodes. Other than that it looks fine to me.


I believe “dhayes” is on the right path to identifying the problem: you have created new ports (by the calls to CreatePort()), but you haven’t added those ports to any node or added them to any document.
GoBasicNode automatically calls CreatePort for you (the method is there primarily for convenience in overriding, which is why it is protected–did you make it public in your subclass?). So the node will already have a port, which you can access via the Port property on the node.
So you just need to do something like:
myView.CreateLink(maNode.Port, miisNode.Port);
instead of the six lines starting with a call to CreatePort().