Moving a GoGroup that contains GoLabelledLink

I select two GoGeneralNodes and one GoLabelledLink and attempt to
create a group. It seems to work, with new bounding box
surrounding the three objects. But… when I select the group and
try to move, the link does not move properly. It loses physical
connection to the node ports and sometimes is placed outside the
bounding box of the group. If I then ungroup the selection and
move one of the nodes, the link corrects itself. What do I have
to do to move a group that contains links?

Are you making the group in the same way that the GroupSelection method does in GraphView of Demo1? You have to make sure that the link is a child of the parent node, along with your two GoGeneralNodes.

Well… sort of. I started with the code from Demo1, however in
my model I place the links on layer beneath the nodes. If I use
demo1 code I lose the link, but if I create the GoNode, add all the
selected objects to the group, and THEN add the GoNode to the document,
the link is included. (vs order in Demo1 of create GoNode, add to
document, move all objects into the group)

I don’t understand – the code in Demo1 handles links starting off in a different layer from the nodes. You are calling AddCollection, aren’t you?

No. The sample code that I have for Demo1 does not use
AddCollection. I have GoDiagram 2.2.1 and GraphView.cpp is dated
3/4/2004 . Where can I access more recent Demo1 code?

This is from the current release, 2.6. I hope this all works in 2.2, although I don't think it has changed since then.
// make a group out of the current selection
public void GroupSelection() {

GoSelection selection = this.Selection;
GoNode group = new GoNode();
// now add the group to the document
GoDocument doc = this.Document;
doc.Add(group); // add all selected objects to the group
IGoCollection coll = group.AddCollection(selection, false); // update the selection too, for the user's convenience
selection.Select(group); // make each child object not Selectable
foreach (GoObject child in group) {
child.Selectable = false;
} FinishTransaction("Group");
// this action only works on the primary selection, which should be a group
public void UngroupSelection() {
StartTransaction(); GoSelection selection = this.Selection;
GoObject first = selection.Primary;
if ((first != null) && (first is GoGroup) && first.IsTopLevel) {
GoGroup group = (GoGroup)first;
GoLayer layer = group.Layer;
selection.Clear(); // special cases for subgraphs--don't promote Handle or Label
// or other special subgraph children as stand-alone objects
GoSubGraph sg = group as GoSubGraph;
IGoCollection coll;
if (sg != null) {
GoCollection children = new GoCollection();
foreach (GoObject child in sg) {
if (child != sg.Handle && child != sg.Label && child != sg.CollapsedObject && !(child is IGoPort)) {
coll = layer.AddCollection(children, true);
} else {
coll = layer.AddCollection(group, false);
} // make each child object Selectable
foreach (GoObject child in coll) {
child.Selectable = true;
} // delete the group
} FinishTransaction("Ungroup");

This new code correctly creates the group with nodes on one layer and
link on another, but still has the problem of incorrectly painting the
link when the group is moved (back to the original posting problem)

Ah, try adding this override to your “group” class:

protected override void MoveChildren(RectangleF prevRect) {
float dX = this.Left - prevRect.X;
float dY = this.Top - prevRect.Y;
foreach (GoObject obj in this) {
if (obj is IGoLink) {
RectangleF r = obj.Bounds;
obj.Bounds = new RectangleF(r.X + dX, r.Y + dY, r.Width, r.Height);
foreach (GoObject obj in this) {
if (!(obj is IGoLink)) {
RectangleF r = obj.Bounds;
obj.Bounds = new RectangleF(r.X + dX, r.Y + dY, r.Width, r.Height);
This code got moved up from GoSubGraph to GoNode in version 2.3, to handle situations like this where it isn't a GoSubGraph but some other GoNode class that contains links.

That’s it! All is working as expected now. Thanks.