Drag over node to org chart diagram problem

The application that I am working on has a node palette on the left and an organization diagram on the right pane. When the node in the palette is dragged over to a node on the diagram, it dropped as a child of the node (on the diagram). I can see that the new node’s parent is correct (by showing the node id and parent node id in the node template). However, after I saved the diagram by clicking on the 'Save" button and refreshes the page, it looks like that the node is added to the diagram as an orphaned node and lost its parent node. Which event handler should I use the code in to save the parent node id before saving the model?<?:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /><o:p></o:p>

Are you using go:Part.DropOntoBehavior=“AddsLinkFromNode” (or AddsLinkToNode)? If you are, then the DraggingTool.DropOnto method automatically calls the IDiagramModel.AddLink method. If it hasn’t generated any error messages (check trace listener output), then the model really was changed and the model data should reflect it.

If you look at the “saved” diagram data, does it have the parent information that you would expect?

I do have the go:Part.DropOntoBehavior=“AddsLinkFromNode” set in the diagram. The problem is this. I used goXaml mode.changed event handler to save the new node data to an object (entity framework context object) each time the model is changed. It looks like that when the node from the palette is dragged over to the diagram panel, the model changed event is detected and the event handler is called. At this point, the node has not landed on its parent node yet, therefore, the parent node id is null at this point. How can I delay add until the node is dropped onto the target node?<?:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /><o:p></o:p>

Eventually you’ll get a Changed event with a ModelChange describing the link that was added or the parent reference that was modified, depending on what kind of model you are using.

I am using the TreeModel. ModelChange.AddedLink is never fired.

As you can see in the documentation, ModelChange.AddedLink only applies to a GraphLinksModel, not to a TreeModel. For a TreeModel you want to check ModelChange.ChangedParentNodeKey and AddedChildNodeKey and RemovedChildNodeKey.

I was able to find the parent node using LastMousePointInModel to find the parentNode key in the ExternalObjectDropped event and add the node to the diagram and save it here. But there is another problem. The ModelChange.RemoveNode is constantly called when a node is dragging from the palette so I would have to not putting any code with ModelChanged.RemoveNode event. Then user won’t be able to remove node from the diagram. Now I am stuck here.

That’s because during the drag operation there is a temporary node that is added. It is removed at the end of the drag operation. If the drop occurs the permanent node is added.

Thanks for your suggestion. It looks like that add handler to ModelChange.AddedChildNodeKey solved the problem. I have to do more testing though.