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.

Ignore TreeViewAdv.Root

Thread ID:

Created:

Updated:

Platform:

Replies:

92967 Feb 16,2010 01:25 PM Feb 18,2010 10:11 AM Windows Forms 3
loading
Tags: Tools
David
Asked On February 16, 2010 01:25 PM

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?

Thanks.

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

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

David
Replied On February 17, 2010 12:33 PM

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...

[CategoryNode1]
[child]
[child]
[CategoryNode2]
[child]
[child]
[CategoryNode3]
[child]
[group]
[child]

...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.

Thanks.

Rajasekar B [Syncfusion]
Replied On February 18, 2010 10:11 AM

Hi,

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;
}
else
{
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.

Thanks,
Rajasekar



treeview_c53a7dd2.zip

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.

;