When can i add something to a document

I want to initialize a GoView with some items already in place… is
there a time when its best to add stuff to a Document? I get weird
scrollbars when adding an item before the document is shown…

Any time should work fine, but if you set GoDocument.SuspendsUpdates to true temporarily while you were initializing the document, it’s likely that the document’s TopLeft and Size properties hadn’t been updated. So you’ll need to set them yourself, manually. Something like:
RectangleF b = doc.ComputeBounds();
doc.Size = b.Size;
doc.TopLeft = b.Location;

I’m getting the same “weird scrollbars”, the first time nodes are added to the diagram. I’m using the following code when dropping an item onto the canvas…

try {
RectangleF b = Document.ComputeBounds();
Document.Size = b.Size;
Document.TopLeft = b.Location;
Document.BeginUpdateViews();

// code to add nodes
} finally {
Document.EndUpdateViews();
}

Immediately upon dropping the first node, a small horizontal scrollbar appears in the middle of the canvas and remains until the view starts drawing itself. Subsequent drops do not cause this.

if you remove the Begin/End UpdateViews, is there a problem? Note what you’re doing just prevents painting, but if you are adding all the objects at once, there isn’t any painting happening until that “thread” ends anyway. (i.e. I don’t think the Begin/End here is going to make things faster)

you should be doing the ComputeBounds/Size/Location AFTER adding all the objects.

I changed it to this:

try {
Document.BeginUpdateViews();
Document.SuspendsUpdates=true;

// code that adds nodes

} finally {
Document.SuspendsUpdates=false;
Document.EndUpdateViews();
}

This seems to have fixed it.

Good…but now I’m curious… how many nodes & links are you adding? And is it really faster with the suspend updates?