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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Ignore TreeViewAdv.Root

Thread ID:





92967 Feb 16,2010 06:25 PM UTC Feb 18,2010 03:11 PM UTC WinForms 3
Tags: Tools
Asked On February 16, 2010 06:25 PM UTC

Hi, I'm adding some drag and drop functionality to my TreeViewAdv and most of it is working great. The only problem is that I don't want to be able to drag/drop anything onto the 'ROOT' of the tree.

I have 5 seperate categories that act as roots for each type of object, and so I don't want any nodes to be able to leave it's own category node.

How can I prevent nodes from dragging/dropping onto the treeview's root?


Administrator [Syncfusion]
Replied On February 17, 2010 10:45 AM UTC

If you use the DragOver event for a control you can get the node at the mouse location and then change the DragDropEffects to stop/allow the drop.

Dim poiMouseLocation As Point = TreeView.PointToClient(New Point(e.X, e.Y))
Dim nodNode As TreeNodeAdv = TreeView.GetNodeAtPoint(poiMouseLocation, True)
If Not nodNode Is Nothing Then
If nodNode.Level > 1 Then
e.Effect = DragDropEffects.Move
End If
End If

Replied On February 17, 2010 05:33 PM UTC

hmm, that doesn't seem to work.

Can any of the syncfusion team provide a sample (C#) that allows me to restrict dragging of a node so that it can only be dragged within its parent node. Like this...


...So the child nodes can be dragged anywhere as long as it is dragged within its category. The child nodes can also be dragged inside a group node.


Rajasekar B [Syncfusion]
Replied On February 18, 2010 03:11 PM UTC


You can change the dragdropeffect by checking whether the dragged node's parent and the node's parent at the mouse point are same. If true, dragdropeffect will be move or copy etc but if it is false, dragdropeffect will be none.
In drag over you can change the effects
private void treeViewAdv1_DragOver(object sender, DragEventArgs e)
TreeNodeAdv sourceNode = null;
if (e.Data.GetDataPresent(typeof(TreeNodeAdv)))
sourceNode = e.Data.GetData(typeof(TreeNodeAdv)) as TreeNodeAdv;
TreeNodeAdv targetNode = this.treeViewAdv1.GetNodeAtPoint(this.treeViewAdv1.PointToClient(new Point(e.X, e.Y)));
if (sourceNode != null && targetNode != null)
if (!CanDrop(sourceNode, targetNode))
e.Effect = DragDropEffects.None;
e.Effect = DragDropEffects.Move;

You can use following method to check both node's parent are same,

private bool CanDrop(TreeNodeAdv sourceNode, TreeNodeAdv destinationNode)
if (sourceNode.Parent == destinationNode.Parent)
return true;
return false;

Let me know if this helps you.




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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon