LayoutChildren called BEFORE constructor?

I have extended a GoBasicNode and added a few GoTextNodes to it. Displays fine, for however many rows of GoTextNodes I want. But I want to make sure the ports for each GoTextNode displays and are active (and am having a tough time figuring it out.)

To that end, after scouring the forum and help files, I have overriden the LayoutChildren method. Funny thing is, the LayoutChildren method is called BEFORE the constructor. Which throws and error cause the LayoutChildren refers to a collection of GoTextNodes, but since the constructor hasn't been called, the collection doesn't exist yet. Is that actually what is supposed to happen? LayoutChildren is called BEFORE the constructor? Is there any way around this?

If your nodes appear the way you want them, you don’t need to override LayoutChildren unless you want it to handle the effects of changes – for example size changes to any of the children or removing or adding any children.

It doesn't make sense that a non-static method can be called before the constructor on which that method would operate.
However, if you are adding or modifying children in your node's constructor, LayoutChildren will be called. Maybe that is what you are seeing.
It's common to set GoObject.Initializing to true at the beginning of such a constructor, and at the end of the constructor set it back to false and then call LayoutChildren(null). Your LayoutChildren method should then be a no-op when Initializing is true.

By the way, is there a reason you aren’t using the GoMultiTextNode? Or are you trying to arrange those child GoTextNodes in some other manner?

That seems like the likely cause of the problem, assuming that simply declaring a GoTextNode (and setting its appearance) within the constructor of a GoBasicNode qualifies as adding children.
So then, how can I make sure that the ports for the added GoTextNodes are enabled (they are visible). Right now, when I link from a simple GoBasicNode to my extended one, it only points to the extended one's node. Is there some way I can 'turn off' the port node for the extended node, and then turn on the ports for the GoTextNodes?
I can supply my code if it helps, so you can see what I'm doing. But basically, I have a single GoBasicNode, with a rectangle shape. The children of the GoBasicNode are:
1) another GoBasicNode (also rectangular, but extending up around the label of the parent GoBasicNode.) I'd like to put a port on that that is linkable.
2) Then I have a collection of n GoTextNodes, whose width and appearance is governed by the width of the Parent GoBasicNode label (or their own, depending on which is larger). I'd like to have the right ports on these be linkable as well.

Well, this little project is something I’m working on the side, for myself (but not limited to one computer). Basically, a DB mapping tool, allowing data from one or more DB to be mapped to another. Thus, I want to recreate the DB table structures as nodes, with the columns as textboxes, similar to RecordNode. That way, users can visually map database tables AND columns (and other functions, and static values) to a target DB. After validating the designed schema, it can then be executed.

But since is an inhouse project (and we don't have a need, as yet, for any other diagramming) my work isn't going to go for the GoDiagram for Win. So I have to make do.

So the GoTextNodes are not children of the GoBasicNode. OK. But then GoBasicNode.LayoutChildren won’t get called each time you create GoTextNodes.

I'm not sure how much you want to "turn off" the ports, and when. There's any number of possibilities: remove the port, make it not Visible, or set GoPort.IsValidFrom and .IsValidTo. You'll need to decide what's best for your app.
'Turn off' may be the wrong word. But basically, I want to create similar functionality to a GoMultiTextNode or its extended RecordNode.
In my situation, I'd like to either link the whole thing (the child or parent GoBasicNode itself) at the top left corner. Or I'd like to link the individual GoTextNode boxes.
As things are now, I can ONLY link to the Parent goTextNode, though in the top corner, as I want. But I cannot get any of the children nodes to link.
here's my code:
[code] [Serializable] public class GoDBRecord : GoBasicNode { public GoBasicNode goDataTable;//outer rectangle public ArrayList goDataColumns;//list of GoTextNodes public GoTextNode goDataColumn;//temp GoTextNode holder private float greatestWidth;

public GoDBRecord(PointF loc, int numCols, string text) : base() {
this.Text=text;
greatestWidth=this.Label.Width;
goDataColumns=new ArrayList();
//create inner rectangle
this.Shape=new GoRectangle();
this.Copyable=true;
this.Location=loc;
//create columns
for(int i=0;i<numCols;i++){
GoPort port=new GoPort();
port.Style=GoPortStyle.TriangleMiddleRight;

goDataColumn=new GoTextNode();
goDataColumn.Text=“Data Column “+i+”-”;
goDataColumn.Location=getColLoc(i);
if(goDataColumn.Width>greatestWidth){
greatestWidth=goDataColumn.Width;
}
goDataColumn.Label.Width=greatestWidth-8;
goDataColumn.RightPort=port;

goDataColumns.Add(goDataColumn);
}
this.Shape.Width=greatestWidth;
this.Shape.Height=(numCols*20);
//create outer rectangle
goDataTable=new GoBasicNode();
goDataTable.Shape=getTableSize();
goDataTable.Location=getTableLoc();
this.Port.ToSpot= GoObject.TopRight;
this.Port.FromSpot=GoObject.BottomRight;
}

public override void Paint(Graphics g, GoView view) {
base.Paint (g, view);
//paint outer rectangle
goDataTable.Location=getTableLoc();
goDataTable.Paint(g,view);

//paint columns
for(int i=0;i<goDataColumns.Count;i++){
goDataColumn=(GoTextNode)goDataColumns;
goDataColumn.Location=getColLoc(i);
goDataColumn.Paint(g,view);
}
}
public PointF getColLoc(int i){
PointF oldP=this.Location;
return new PointF(oldP.X-this.Bounds.Width/2, (oldP.Y-this.Bounds.Height/2)+(20*i)+9);
}
public PointF getTableLoc(){
return new PointF(this.Location.X, this.Location.Y-this.Label.Height/2);
}
public GoRectangle getTableSize(){
GoRectangle oldRec=(GoRectangle)this.Shape;
GoRectangle newRec=new GoRectangle();
newRec.Width=oldRec.Width;
newRec.Height=oldRec.Height+this.Label.Height;
return newRec;
}
}[/code]

Sorry for the inconvenience. I appreciate any help you can give.

Please don’t take this the wrong way, but I think the design is getting ugly. You are going to have problems dealing with copying and deleting, but that might not matter, depending on what you allow users to do.

GoTextNode already has ports, so you don't have to create them.
But you do need to add the GoTextNodes that you create to the document, in order for the user to be able to interact with them. You don't need to override Paint.

lol. No I am not offended. I’m not gonna pretend this is the best way. I know its kind of a hack. Necessity and all that, after all.

So I followed your suggestion and added all the 'children' (since I don't think they are technically children) to the doc. Now I can link to the individual nodes. Only thing is, it won't move, when I drag it. So just one more step, I think...
You guys are great, by the way. I appreciate your help.
edit to add:
when I comment out the entire paint method, the image doesn't display correctly. Moreover, when I drag an element, only that element moves, thus taking the thing apart. The advantage of using the paint method was that dragging it took the entire thing as a whole. But when I restore the paint method and then drag, it won't move. Or rather, a child element moves, but then returns to its original position.
My guess is that I need the parent GoBasicNode to be transparant and on top. But I wonder if that will affect the ports of the child nodes...
I realize this is cludgy.

Ok, got the entire node to move and copy. And I can link to a node I have created programmatically, since each individual GoTextNode gets the focus. But when I copy the entire extended GoBasicNode (and make sure the copy is added to the document), then neither the original GoBasicNode or the copy will let the focus be on the individual GoTextNodes. So I can’t link from those nodes to another node. I wonder if it has something to do with the layer the parent GoBasicNode is in? I guess the best thing would be for the GoTextNodes to be on a layer above the parent GoBasicNode, that way they can always be focused on.

hmmmm....

Ok, got just about everything working the way I want it. Only thing left is to position a port on the top right of a square node. In looking up the FAQ, I found out that the LayoutChildren is undoing any port positioning I do. So I have to override it. But I run into the problem of the LayoutChildren method being called before the constructor. Probably, as you said, some of the modifications I do in the constructor are calling the LayoutChildren method too early.

I followed your suggestion above that I set the this.Initializing=true in the constructor, then at the end LayoutChildren, then this.Initializing=false. But it still gets called first. I don't see anywhere other reason the LayoutChildren method is called before objects in the constructor are initialized.