Node color change


1)How to get node id of selected node?
2)How dynamically change selected node color ?
I am using GoDiagram in

following is my code:-
Here i get selected node text. But I want to get selected node id and change selected node color.

GoObject obj = MyView.PickObject(true, false, MyView.LastInput.DocPoint, true);
if (obj == null) obj = MyView.Selection.Primary;
IGoLabeledNode lnode = obj as IGoLabeledNode;

        if (lnode != null)
            if (lnode.Label.Multiline)
                lnode.Label.Text = LabelTextArea.Text;
                lnode.Label.Text = LabelTextBox.Text;

1) node.PartID

2) if you really want the selected node, you shouldn’t have to call PickObject, just use Selection.

> IGoLabeledNode lnode = obj as IGoLabeledNode;

You need to "as GraphNode" to get to the Shape property and change color.
Look at the GraphNode code to see how colors are set on nodes.


        this.Shape.FillShapeHighlight(<wbr>first, second);

I have changed node color using following code, But node.PartId cant return node Id. Every time return -1.

GoObject obj;
obj = MyView.Selection.Primary;
GraphNode lnode = obj as GraphNode;
if (lnode != null)
if (lnode.Label.Multiline)
lnode.Shape.BrushForeColor = Color.Red;
var id = lnode.PartID;
var nodeId = id;

From the User Guide section “Supporting Save and Load”

To simplify the generation of unique IDs for nodes and ports and links, GoDocument has a property that automatically makes sure that each node, port, or link that is added to the document has a unique PartID. Just set the GoDocument.MaintainsPartID to true. All objects that implement the IGoIdentifiablePart interface provide a PartID property; this is set by GoDocument as objects are added to the document.

When you need to refer to objects, such as to the ports of a link that you are storing, you can just pass the PartID. Upon loading, you can find the IGoIdentifiablePart in the document with

that ID by calling GoDocument.FindPart. Remember to save the LastPartID in your document too, to avoid any possible duplicate PartIDs.