How do i remove specific link from godocument

I have nodes and links in GoDocument I want to remove specific link from the linklayers how do i achieve this


Depending on context, you may want to wrap in a StartTransaction / FinishTransaction.

how to find specific link obj? from godocument
mean i want to get link obj which is having fromport =1 and toport=2

Depends on your context. What defines this as the “specific link”?

If the link is selected, you can just call goview.DeleteSelection(null).

If you have GoDocument.MaintainsPartID on, you can do RemovePart(partID) if you somehow know the unique partID of the link.

or you can iterate the document looking

foreach (GoObject obj in aDocument) {
IGoLink link = obj as IGoLink;
if (link != null) {
// do something with the IGoLink link,
// which is typically a GoLink or a GoLabeledLink

I m able to remove link through looping on GoDocument but is their any another way to find linkobj from GoDocument just like findnode from GoDocument without looping in godocument

I can easily FindNode by name from GoDocument as below

and it is working fine.

No. Simple GoLink doesn’t have a Text (or Name) so there isn’t a FindLink (text).

Actually, FindNode looks for objects that implement IGoLabeledPart, which GoLink and GoLabeledLink do not implement. But you could derive your own link class and add IGoLabeledPart and a Text Property, and then FindNode would work, as FindNode returns a GoObject.

I am using maintainPartId on document, i have provided unique part id to every link
as suggested you earlier solution RemovePart(partID) I am finding
GoObject obj = (GoObject)document.FindPart(2);
then remove this object from document

but it remove node and two link from findpart=2

i want to remove only single link with the unique part id= 2 from my godocument object
how can i achieve this?

If you are using maintainsPartId, you shouldn’t be providing ids… GoDiagram will do that for you.

Thanks for the input for maintainsPartid with auto id I was able to find linkobject
but before i need to strore that partid on my db. I wanted to go with inmemory approach for add and remove nodes and links in godiagram, for inmemory how do I get which link having what partid so I can remove that link using partid.

note: I have not stored godocument nodes and links to any where it is inmemory only.
on inmemory only I want to add remove link from GoDocument object

It feels like we’re going in circles here. PartID uniquely identifies Nodes and Links, and RemovePart(pairtid) will remove that GoObject from the diagram.

How you decide which link to delete is an application issue. I don’t know your application.

refer screen shot of my application requirement user has created 4 nodes and 4 links on diagramscreen which is povided in my application now user want to remove link which is connected from 1 to 4 that the only thing i required using goDocument but it is in inmemory
because until user do not click save i am not storing this diagram to any where

OK, so you know the two nodes and you want to find the link.

It’s different if you want to find ANY link between 1 & 4, or just links FROM 1 TO 4. It sounds like you want the later, so…

Find Node 1, then GoNode.DestinationLinks will return “an enumerator over all of the links going out of this node.”

then just iterate that collection of links, check the link.ToNode to see if it is “4”.

If it is, delete the link.

There is a section in the User Guide on diagram traversal, details there.