We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Dragging nodes from a Diagram to another control

Thread ID:

Created:

Updated:

Platform:

Replies:

110217 Jul 24,2013 10:02 PM Aug 5,2013 07:15 AM Windows Forms 4
loading
Tags: Diagram
Dylan Black
Asked On July 24, 2013 10:02 PM

I have a requirement to drag nodes from a Diagram to other Windows Forms controls, including other diagrams.
I've tried overriding the OnDragLeave and OnMouseLeave methods of the Diagram, but it appears that these are being blocked during a node move operation.
I've noticed other forum posts around this topic from several years ago, when it was acknowledged as a known issue, and was wondering if it has been resolved, or if there's some way to implement this now.
Thanks.

Amsath Ali M [Syncfusion]
Replied On July 25, 2013 08:21 AM

Hi Dylan,

 

Thanks for your interest in Syncfusion products.

 

We are glad to inform you that we have achieved your requirement by creating a custom tool called “DragDropTool” and activated the custom tool to drag and drop an element from diagram into treeview control. Please refer the below code snippet.

Here is the code:

[C#]

public Form1()

{

    InitializeComponent();

    DragDropTool tool = new DragDropTool(this.diagram1.Controller);

    diagram1.Controller.RegisterTool(tool);

    this.dragHelper = new DragHelper();

    treeView1.AllowDrop = true;

 

    treeView1.MouseDown += new MouseEventHandler(treeView1_MouseDown);

    treeView1.MouseMove += new MouseEventHandler(treeView1_MouseMove);

    treeView1.MouseUp += new MouseEventHandler(treeView1_MouseUp);

    treeView1.QueryContinueDrag += new QueryContinueDragEventHandler(treeView1_QueryContinueDrag);

    treeView1.GiveFeedback += new GiveFeedbackEventHandler(treeView1_GiveFeedback);

    treeView1.DragDrop += new DragEventHandler(treeView1_DragDrop);

    treeView1.DragEnter += new DragEventHandler(treeView1_DragEnter);

 

    diagram1.DragEnter += new DragEventHandler(diagram1_DragEnter);

    diagram1.DragDrop += new DragEventHandler(diagram1_DragDrop);

    diagram1.MouseDown += new MouseEventHandler(diagram1_MouseDown);

    diagram1.Model.EventSink.PinPointChanging += new PinPointChangingEventHandler(EventSink_PinPointChanging);

    this.Disposed += new EventHandler(Form1_Disposed);

}

 

void diagram1_MouseDown(object sender, MouseEventArgs e)

{

    Node node = this.diagram1.Controller.GetNodeUnderMouse(e.Location) as Node;

    if (node != null && diagram1.Controller.ActiveTool is DragDropTool)

    {

        DragDropData data = new DragDropData(node);

        data.DragNodeCueEnabled = bDragNodeCueEnabled;

        diagram1.DoDragDrop(data, DragDropEffects.Copy);

    }

}

 

void treeView1_DragEnter(object sender, DragEventArgs e)

{

    e.Effect = DragDropEffects.Copy;

}

 

void treeView1_DragDrop(object sender, DragEventArgs e)

{

    TreeNode nodeToDropIn = this.treeView1.GetNodeAt(this.treeView1.PointToClient(new Point(e.X, e.Y)));

    if (nodeToDropIn == null) { return; }

    if (nodeToDropIn.Level > 0)

    {

        nodeToDropIn = nodeToDropIn.Parent;

    }

    object data = e.Data.GetData(typeof(DragDropData));           

    nodeToDropIn.Nodes.Add(((DragDropData)data).Nodes[0].Name);

    e.Effect = DragDropEffects.None;

}

 

DragDropTool.cs:

 

class DragDropTool:ZoomTool

{

    internal static string ToolName = "DragDropTool";

    public DragDropTool(DiagramController contllr)

        : base(contllr)

    {

        //Ser Arrow as Tool's action cursor

        this.ActionCursor = Cursors.Arrow;

        this.Name = ToolName;

        this.SingleActionTool = false;

    }

 

    public override Tool ProcessMouseDown(MouseEventArgs evtArgs)

    {

        Tool toolToReturn = this;

        if (this.Controller.Viewer != null && this.InAction)

        {

            this.InAction = false;

        }

        return toolToReturn;

    }

}

 

 

Please try the below attached sample and let us know if you have any queries.

 

Regards,

Amsath Ali. M

 



Treeview_14da86bb.zip

Dylan Black
Replied On July 26, 2013 01:27 AM

Hi,

Thanks for getting back to me with a sample.
I can get the drag & drop to work if I use the Syncfusion DragDropData type as the argument to DoDragDrop, but if I change it to the regular .NET DataObject class, and pass a custom type as the data (i.e. not a NodeCollection or DragDropData) then the cursor flickers constantly.
Since I'm using the Diagram as part of a larger application, I  ideally need to use the DataObject class along with our own entity classes to maintain compatibility with other parts of the system.
I've updated the sample to show what I mean; the cursor flickers when you drag from the TreeView to the Diagram.
My guess would be that the code in the Diagram OnDragEnter method, which is setting a private boolean based on those passed in data types, is responsible.

Do you have any ideas on how to prevent the cursor flickering?

Thanks,
Dylan.



Treeview_6a5c1c96.zip

Dylan Black
Replied On July 26, 2013 01:41 AM

I should add that when I use the DragDropData type during the drag operation that the diagram attempts to automatically insert the nodes that it contains on drop, which I don't want to happen - I would need to be able to override this if I am forced to use the DragDropData type to prevent the cursor flickering.

Amsath Ali M [Syncfusion]
Replied On August 5, 2013 07:15 AM

Hi Dylan,

 

Thanks for your update.

 

We are able to reproduce the issue reported by you at our end, and the issue has been suspected to be a defect. Please create a DT incident for your query so that we can update the patch for this issue.

You can create the DT incident from the following link.
<
http://www.syncfusion.com/account/dashboard>

In the interests of maintaining confidentiality, we have a policy of not sharing patches or otherwise proprietary customer specific information in the public Forum.

 

Please let us know if you have any queries.

 

Regards,

Amsath Ali. M


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;