Drag and Drop issue

Hi,

I have created my diagram based on “Planogram” example. My requirement is when i drag an object

from one group to other it should not be dragged. i have implement custom dragging tool in the following way

public class MyDraggingTool : DraggingTool
{

    /// <summary>
    /// To check whether the node is a ValidMember or not.
    /// </summary>
    /// <param name="group">The Group to check.</param>
    /// <param name="node">The Node to verify.</param>
    /// <returns>The status Boolean.</returns>
    public override bool IsValidMember(Group group, Node node)
    {           
        var parent = (group as Part).Data as FPDSymbolDataVM;            
        if (node != null)
        {                
            //For category other than Text Restricted area should work.
            if (parent.Key == "Rack2")
            {
                    DoCancel();
                   return false;
            }             
        }
        return base.IsValidMember(group, node);
    }

///Palette dragging
protected override bool MayCopyExternal(DragEventArgs e)
{
// check standard cases
if (!base.MayCopyExternal(e)) return false;
// see if the mouse is over a Group
Part overgroup = this.Diagram.Panel.FindElementAt(this.Diagram.LastMousePointInModel,
Part.FindAncestor, p => true, SearchLayers.Parts);
if (overgroup == null) return false;

      var node = overgroup.Data as MyNodeData;
      if (node.Key == "Rack4")
      {
          return false;
      }
      // maybe look at the e.Data to reject additional cases
      return true;
  }

  protected override bool ConsiderDragOver(Point pt, Part p)
  {
      var item = p.Data as MyNodeData;
      if (item.Key == "Rack4")
      {
          DoCancel();
      }
      return base.ConsiderDragOver(pt, p);
  }

}

But some times I can drag and drop the node on other groups. and it while releasing the mouse it is creating the copy of that object. How can i avoid these issues?

I’m sorry, but I don’t understand your requirement: [quote]My requirement is when i drag an object from one group to other it should not be dragged.[/quote]

If you don’t want a node to be moved or copied, set go:Part.Movable=“False” and go:Part.Copyable=“False”. That would be much better for the user than allowing the drag to get started and then have to prevent any drop from happening.

Also, calling DoCancel within those methods is going to cancel the whole dragging operation, which is not the point of the IsValidMember predicate. Just returning false should prevent the drop from being reparenting the dropped object to be a member of the new Group.

Hi Walter,

Sorry it is my mistake, I have an area which should act as a restricted area for some control( say Category = Box) and if i drag one control (which is placed in a group) to this restricted area location (Different Group) it should not be allowed to drag and drop , I am expecting Something similar to MayCopyExternal behaviour

Reagrds

Are you saying that for such nodes you want to allow the user to drop at other locations, but not in some of them?

Then you don’t want to call DoCancel in predicates such as IsValidMember or ConsiderDragOver. That would just terminate the dragging operation without giving the user a chance to drop somewhere else. I believe you’ll want to cancel the operation only when there’s been a drop. That would be in the DropOnto method.

You might also be able to prevent a drop from happening, but that depends on the platform and the permissions and whether it’s an internal or an external drag-and-drop.