Ignore TreeViewAdv.Root
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.
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.
SIGN IN To post a reply.
3 Replies
AD
Administrator
Syncfusion Team
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
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
DA
David
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...
[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.
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.
RB
Rajasekar B
Syncfusion Team
February 18, 2010 03:11 PM UTC
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
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
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
DA David
- Feb 16, 2010 06:25 PM UTC
- Feb 18, 2010 03:11 PM UTC