SubGraph Dragging

I am trying to figure out how to enable the user to drag and drop a subgraph. I have converted the SubGraphApp sample application code for the SubGraphDraggingTool into VB.NET and I am attempting to use it in the same way. However, I keep getting an error.
This code runs fine:
Dim tool As SubGraphDraggingTool = New SubGraphDraggingTool(Me)
tool = CType(Me.FindMouseTool(GetType(SubGraphDraggingTool)), SubGraphDraggingTool)
But when I try to run the following code it gives me a System.NullReferenceException error:
Dim whole As GoSelection = New GoSelection(Me)
whole = tool.ComputeEffectiveSelection(col, True)
I have tried everything I can think of and I have been studying the SubGraphApp sample application closely. But I am still missing something.
Do you know of any common mistakes users have made in the past when attempting to enable dragging and dropping for subgraphs? Or maybe you can tell from the small sample of my code what my hangup might be? I’m sure it’s something simple but I just can’t see it.
Any advise would be greatly appreciated! Thanks!
Joy

That tool isn’t meant to change the dragging-and-dropping of subgraphs, in particular, but of all objects, so that they can perhaps be dropped “into” subgraphs.
We have converted most of the samples into VB.NET. See the sticky “Important Topic” in this forum, “Welcome (NEW: VB.NET samples & SVG/XML)”, http://www.nwoods.com/forum/forum_posts.asp?TID=14&PN=1.

Thank you! That helped a lot - looking at the code in VB helped me to track down my problem
But now I have encountered another issue. When I set the subgraph.CollapsedObject to an image of my choosing, the first time it displays the subgraph in its expanded form, it displays this object and hides my background and borderpen properties. But every time after that when I expand and collapse the subgraph is only displays the CollapsedObject when the subgraph is collapsed. Do you have any idea why this is acting differently the first time I display the subgraph?
Joy

If you set GoSubGraph.CollapsedObject when it IsExpanded, I guess you should also set the collapsed object’s Visible and Printable properties to false.
In the next release, we’ll do that for you, in the CollapsedObject setter.

Thank you! One more quick question - I am having hard time figuring out how to manipulate the size of a subgraph. Right now it’s very big and each time a collapse and expand it it gets bigger and bigger (which I don’t understand since that doesn’t happen in the SubGraphApp and I copied code straight from that application to my own). Any ideas??

No, sorry, I can’t tell what your code is doing.
To help debug this, you might want to examine the behavior CollapseChild and ExpandChild, and look at the SavedBounds hash table to see what sizes and positions have been stored for the children.

ok - let me ask you this - how can I manipulate the size of a subgraph without distorting the objects inside the subgraph? I have tried subgraph.size and everything else I could find and it wouldn’t change the size of the subgraph but it would distort the shape of the objects inside it.

By definition the bounds (and thus the size) of a GoGroup is just the union of the bounds of its children. Changing the size of a group, by default, will adjust the sizes of all of the children proportionately.
However, GoSubGraph adds the TopLeftMargin and BottomRightMargin properties to provide some extra room around the children. So you can just modify those properties in order to change the size of the subgraph without moving or resizing any of the children.

Ok, I think I have figured out the problem, the nodes in my subgraph have user objects which are not serializable - that seems to be messing up the size of the subgraph.
So now I need to loop through the nodes and links in my subgraph to remove their user objects - I have tried using subgraph.Nodes but that just gives me an error. Is there an easy way to iterate through the nodes and links contained in a subgraph?

A GoSubGraph is a GoNode is a GoGroup that implements IGoCollection. So you can just do a “for each”, and check whether each GoObject is a node or a link so you can decide what to do with it. There are lots of examples in the sample applications–including iterating over the children of a subgraph in the SubGraphApp sample.