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