NTreeViewEx block item drop


Author
Message
Juan de Ituarte López
Juan de Ituarte López
Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)
Group: Forum Members
Posts: 2, Visits: 44

In a NTreeViewEx control I want to be able to block dropping a node to other nodes.
I want to achieve the same result as the default implementation when it blocks me from dropping a node to itself or its parent, but to other nodes of my choice.
How can I achieve this?
Thanks


Reply
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.3K
Hello Juan,

To do this you will need to subclass NTreeViewEx and override ApplyDragDrop method as follows:


public class MyNTreeViewEx : NTreeViewEx
{
    protected override void ApplyDragDrop(NLightUIItemDragDropEventArgs e)
    {
        NTreeNode over = e.DragOverItem as NTreeNode;
        // condition which determines that this is the node(s) that cannot
        // drop another node on it.
        // In this case you can set Tag property of the node to true,
        // or you can choose another approach.
        if ((bool)over.Tag == true)
        {
            return;
        }

        base.ApplyDragDrop(e);
    }
}


Also you can attach the instance of the new class to ItemDrag event and in the event handler you can change the cursor when the user drag over the node that should not accept dropped node:


myNTreeViewEx1.ItemDrag += myNTreeViewEx1_ItemDrag;
...
void myNTreeViewEx1_ItemDrag(object sender, NLightUIItemDragDropEventArgs e)
{
    NTreeViewEx treeView = sender as NTreeViewEx;

    // get the hovered node
    NTreeNode node = treeView.VisibleNodeFromY(e.MousePosition.Y);
    if (node == null)
    {
        return;
    }

    Cursor cur = e.Cursor;

    if ((bool)node.Tag == true && e.Cursor == null)
    {
        e.Cursor = Cursors.No;    
    }
    else
    {
        e.Cursor = cur;
    } 
}


I hope this helps.

Best Regards,
Nevron Support Team


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search