I am trying to connect two objects automatically when one is dropped on the other.
I have overridden the DoExternalDrop method in GoView and tried to use PickObject() to get the object I am dropping onto like in the example code for flowgrammer.
But the object that it keeps getting it the one I am dropping?
I just want to be able to drop a node on another node and connect them. Or drop a node on a link and insert that node into the diagram on that link.
At the moment this is the code I am trying:
Point screenPnt = new Point(evt.X, evt.Y); Point viewPnt = PointToClient(screenPnt); PointF docPnt = ConvertViewToDoc(viewPnt); GoObject over = this.PickObject(true, false, docPnt, false);
If what is being dropped is a GoSelection (i.e. some GoObjects), it is probably easier to implement a GoView.ObjectSelectionDropped event handler. Or override GoObject.OnSelectionDropped on your node and link classes. Some of the example classes demonstrate this.
If what is being dropped comes from some other Control, then you probably do need to override DoExternalDrop. Flowgrammer demonstrates this.
I copied the example in FlowGrammer but it does not seem to be working the same the object PickObject gives me seems to be the one I'm dropping/draging.
What version are you using? Actually, the Flowgrammer sample is relatively recent, so you should definitely have the GoView.ObjectSelectionDropped and related events and corresponding GoObject methods.
The reason PickObject is finding the just-dropped object on top is because you are using the standard mechanisms to get newly copied GoObjects dropped into your GoView/GoDocument. Flowgrammer is handling an external drop from a TreeView, so at the time of the Control drag-and-drop there isn't yet any GoObject that has been copied and added to the document.
Anyway, you probably want to override OnSelectionDropped in your node and link classes.