Thanks for bearing with me... Here's what I think is happening and why... (Perhaps a helpful Sparxian would confirm/deny this).
The reason why the Parent ID is NOT zero in the last case (adding a nested element from a selected browser element by using the context menu - quite a mouthful no?) is that EA can work out easily which element is the parent - it is told by the browser!
In the other cases (dragging onto the diagram from the toolbox), EA can't directly work out the parent. If you drag any element onto any diagram except an Activity Diagram, you don't expect the ParentID to be set. This is because - apart from the special case of the Activity Diagram - diagrams are not directly mentioned in the UML specification.
However, in UML the Activity Diagram IS the Activity. In other words, an Activity Diagram MUST represent the elaboration of the named Activity. Notionally, there can only be one Activity Diagram per activity in the model and every Activity diagram must elaborate only one Activity. Now, I don't know about you, but I - like, I suspect, most modellers - honour this requirement "more in the breach than the observance". That is, we abuse this constraint - regularly.
However, from the point of view of this issue, this constraint may help you solve your problem. EA uses the fact that you're adding the element to an Activity Diagram to determine the parent Activity and assign the parent Activity as the parent of the newly created element.
You should therefore be able to take the DiagramID (remember I initially asked you to check that the DiagramID was correct), check to see if it's an Activity Diagram, then check that the Diagram itself has a ParentID - which means it's an Activity Diagram under an Element (and not one created under a Package). Check the Diagram's Parent Element to see if it it's an Activity and then make your decision...
HTH,
Paolo