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. Image for the cookie policy date

drag node and drop on another node

Hi!

I have another question I am hoping someone can answer.

I have a diagram like the one shown in the attachment. Each node in the diagram is a controlnode that hosts a usercontrol. What I need to do is allow the user to drag one node and drop it on another node and take some action when the drop happens. Could you please give me some hints on how to go about doing this? I've been looking in the forums but most drag and drop involes dragging & dropping from palette to diagram. I don't want that. Rather I need to drag a node and drop it on some other node and take some kind of action when the drop happens.

Thanks much for your help

GA

Doc123.zip

3 Replies

J. J.Nagarajan Syncfusion Team July 27, 2007 01:18 AM UTC

Hi GA,

If you want to fire a event when you drag and drop a node on the existing node then you can write a delegate. Please refer to the following code snippet

public delegate void NodeDragDrop(object sender, EventArgs e);
public event NodeDragDrop nodedragdrop;

public Form1()
{
InitializeComponent();
this.nodedragdrop += new NodeDragDrop(Form1_nodedragdrop);
}
private void diagram1_DragDrop(object sender, DragEventArgs e)
{
if(e.Data.GetDataPresent(typeof(TreeNode)))
{
TreeNode treenode = (TreeNode) e.Data.GetData(typeof(TreeNode));
TextNode textnode = new TextNode(treenode.Text);
textnode.SizeToText(new SizeF(0,0));
textnode.PinPoint = pt;
this.diagram1.Model.AppendChild(textnode);
this.diagram1.Refresh();

if (symbol2.BoundingRectangle.IntersectsWith(textnode.BoundingRectangle))
{
this.nodedragdrop(sender, e);
}
}
}

I have attached the sample that demonstrates this completely. You can download the sample from the following page.

http://websamples.syncfusion.com/samples/Diagram.Windows/F65640/main.htm

Please let me know if you have any questions.

Thanks,
Nagaraj



GA Giancarlo Aguilera July 27, 2007 12:46 PM UTC

Hi,

Thanks for the response.

Your sample is great but it does not illustrate what I need to do. Your sample illustrates dragging a node from one of the controls located OUTSIDE the diagram and then dropping it onto an existing node already on the diagram. What I am looking to do is a bit different. I need to be able to drag a node ALREADY LOCATED on the diagram and drop it on another node that is also ALREADY located on the diagram. For example, say I have a diagram with 2 nodes on it, node A and node B. I need to be able to drag node A and drop it on node B.

Any ideas?


J. J.Nagarajan Syncfusion Team July 27, 2007 03:17 PM UTC

Hi GA,

Thanks for the details. If you want to fire an event when you drag drop a node on the existing node, then you have to write a delegate to fire this event. Please refer to the following code snippet.

//Declare the delegate for NodeDragDrop event
public delegate void NodeDragDrop(object sender, EventArgs evtargs);
//Declare the NodeDragDrop event
public event NodeDragDrop nodedragdrop;

public MainForm()
{
InitializeComponent();
this.nodedragdrop += new NodeDragDrop(MainForm_nodedragdrop);
}

private void diagram1_MouseUp(object sender, MouseEventArgs e)
{
if (this.diagram1.Controller.SelectionList.Count > 0)
{
if(rect.BoundingRectangle.IntersectsWith(symbol2.BoundingRectangle))
{
//Fire Node DragDrop
this.nodedragdrop(sender,new EventArgs());
}
}
}

I have attached the sample that demonstrates this completely. You can download the sample from the following page.

http://websamples.syncfusion.com/samples/Diagram.Windows/DragAndDrop/main.htm

I hope this will meet your requirement. Please let me know if you have any questions.

Thanks,
Nagaraj

Loader.
Live Chat Icon For mobile
Up arrow icon