How to Add Node to Group by code?

Hi Walter,

How can I add/remove a Node to a Group by code?
I need to remove a Node from a Group and put to another Group by code.
Thanks!

myDiagram.StartTransaction("change subgraph membership"); var ndata = someNode.Data as NodeData; var gdata = someGroup.Data as NodeData; ndata.SubGraphKey = gdata.Key; myDiagram.StartTransaction("change subgraph membership");

Or you could call Graph…Model.SetGroupNodeKey.

Thanks, Walter!

But when I use the code aboe, the Node is still sitting in the previous Group. What should I do if I want the Node to be drawn inside the new Group?
Thanks!

Well, the Group.Layout is invalidated and then performed, so it’s responsible.

If you haven’t set the Group.Layout, the default layout is the same as for the Diagram.Layout – it just tries to make sure each node has a Location. Since your node already has a Location, it isn’t changed.

So you’ll need to set the Node.Location, either directly or (if the go:Node.Location is data-bound) by setting the …NodeData.Location property.