Finding a link in Document

Hi Support,

I’m using GoDiagrams 4.1 version.
I’m trying to find an existing link in the document.
I set the MaintainsPartID to true for the document.
I assign PartId to the links when drawing them.

For Example - Assume link.PartID = 1: (using Transition from StateCharter example)

Void CreateLink(string transitionName, DataRow row)

<span =“Apple-tab-span” style=“white-space:pre”> Transition link = new Transition(transitionName);
<span =“Apple-tab-span” style=“white-space:pre”> link.PartID = Convert.ToInt32(row[“TransitionID”]);
<span =“Apple-tab-span” style=“white-space:pre”> Doc.LinksLayer.Add(link);

I try to programatically search the link onclick event on a row in a grid (each row in the grid corresponds to a link in the graph):

object partId = dr[“TransitionID”];
Transition link = wfs.View.Doc.FindPart(Convert.ToInt32(partId)) as Transition;

“link” is null and I found that the FindPart method returns a GoPort object.

Am I doing something wrong?
Thanks in advance!

I assign PartId to the links when drawing them.

That’s where you’re going wrong. MaintainsPartID sets the PartId fields for you.

See the MinimalApp sample

Ok got it!
Even before I add the first link to the document, Document.LastPartID is 68.
So if I set the Link.PartID to anything less than 68 will not work.
Is there a way to “tag” the link with that ID (probably would be less that the LastPartID of the document) and find it from the document using that ID?
I read in the user guide about “UserFlags”. Can I find objects from the document using this?

ok so one more question relating to this:

I was thinking to save the PartID’s that the links get after adding them to the document to the table where all the info relating to the link is kept.

But once the Graph is saved to xml can we retain the same partids when the graph gets loaded again?

I was thinking to spit out the part id’s in to the xml that gets generated when saving, so that when it reloads… the parts get the same part id as they had before they were saved.
I will also be saving this id to the table for reference in future.

You should be able to save the in XML.

for your GoDocument…

  GoDocument doc = new GoDocument();
  doc.MaintainsPartID = true;
  doc.UndoManager = new GoUndoManager();
  bt = new GoXmlBindingTransformer(doc);
  bt.AddBinding("lastpartid", "LastPartID");

for your node, assuming it has one Port.

  bt.AddBinding("PortPartID", "Port.PartID");

and link