Golinks with GoIconicNodes

if I add IconicNodeA, IconicNodeB and IconicNodeC to GoView1:
And if B and C are children of A
How do I add a Golink between them to show the relationship?

GoLink linkAB = new GoLink();
linkAB.FromPort = IconicNodeA.Port;
linkAB.ToPort = IconicNodeB.Port;
GoLink linkAC = new GoLink();
linkAC.FromPort = IconicNodeA.Port;
linkAC.ToPort = IconicNodeC.Port;
Of course you might want to set other properties on the links, such as setting GoLink.ToArrow true.

I’m trying to add the nodes dynamically from a DataView so nodes are not individually declared objects with unique names:
Dim dv As New DataView(Me.MyDataSet.Tables(0))
dv.Sort = “ParentID, ID”

Dim i As Int16 = 0
For i = 0 To dv.Count - 1
MyView.Document.Add(MakeIconicNode(“rocket.ico”, dv(i)(“ID”).ToString(), dv(i)(“ParentID”).ToString(), dv(i)(“Name”).ToString()))
If Int(dv(i)(“ParentID”)) <> 0 Then
'add link from parent to this node and add it to the Goview
End If

Public Function MakeIconicNode(ByVal file As String, ByVal id As String, ByVal parentnode As String, ByVal label As String) As GoObject
Dim n As GoIconicNode = New GoIconicNode()
n.Initialize(Nothing, file, id)
’ labels are editable, but may be disabled by setting myView.AllowEdit to false
n.Editable = True
n.Label.Editable = True
n.Icon.Size = New SizeF(20, 20)
’ port is whole icon. but linking may be disabled by setting myView.AllowLink to false
n.Port.Bounds = n.Icon.Bounds
n.ToolTipText = "Tooltip for " & label
n.Text = label
Return n
End Function

*** Where do I create/add the golink? ***

Where you have the comment:

[quote]'add link from parent to this node and add it to the Goview[/quote]
At that point you just created the “child” node – you just need to find the “parent” node too, so that you can connect their Ports.
First: you aren’t saving the ID anywhere in the GoIconicNode that you allocate – you could use the UserObject or UserFlags properties, if you like.
Second: you need to be able to find a node with a given identifier. The simplest (but slow) solution is to enumerate over all of the objects in the document: if it’s a GoIconicNode, then compare the property where you saved the identifier.
Many of the sample applications do something like what you are doing. There is example code in the User Guide too.

I thought I was saving the ID with: n.Initialize(Nothing, file, id)

Yes, but then you re-set the same property by doing: n.Text = label
That’s because the node’s Text property is by default defined to be the same as the node’s Label’s Text property.

so I have to initialize with the id, hide the text, and add a gotext for what I really want the text to say (the label text)?

Pass the “label” as the third argument to Initialize – that way you don’t have to set the .Text explicitly.
Set the .UserObject property to be the “id” value.
Your iteration through the document to find a particular node would be something like:
Public Function FindNode(ByVal someID as String) As GoIconicNode
For Each obj In MyView.Document
If TypeOf obj Is GoIconicNode Then
Dim n As GoIconicNode = CType(obj, GoIconicNode)
If n.UserObject = someID Then Return n
End If
Next obj
Return Nothing
End Function

Hi. Sorry if my english is not very good. I am Portuguese

and i start to work with GoDiagram in last week.
I´m doing an application that reads from a xml the respectives childrens and fathers, and then build the graph. Each node represents one document that is associated to an ID.
My problem know is how to build the graph but i think i can resolve that problem. One of the solutions it´s using this function findNode to find nodes and then create links between them. How can i associate an ID to a GoIconicNode and then apply this function to find it (if is created)?
I´m working with C#.

Depending on the type of your ID, you can use the GoIconicNode.UserObject property or the GoIconicNode.UserFlags property. If you have a lot of nodes, you may need to keep a mapping of your IDs to these nodes by using a Hashtable, since a linear search through the whole document could be too slow if you do it often.

You might want to look at the code in GraphDoc.cs in the OrgCharter sample, which reads and writes custom XML for an organization chart.
That also makes use of the PartID property on nodes/ports/links that is maintained by GoDocument when GoDocument.MaintainsPartID is true. However, you don't need to use PartID if you have your own ID data type and management of ID values.

Sorry my ignorance but i can´t implement the function findNode in C#. How can i write this two lines in C#:

If TypeOf obj Is GoIconicNode Then
Dim n As GoIconicNode = CType(obj, GoIconicNode)

You can see examples of this code in the section “Traversing a Diagram” in the User Guide.

public GoIconicNode FindNode(String someID) {
foreach (GoObject obj in goView1.Document) {
GoIconicNode node = obj as GoIconicNode;
if (node != null && node.UserObject == someID) return node;
return null;

Thanks Walter.

Like we say in Portuguese "És o maior!!"