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
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
Perfect answer, it works like a charm, thanks!!!!

To make the control generic I've subclassed NTreeViewEx and overrided ApplyDragDrop method as follow to add a new event ItemAllowDrag:

public class MyTreeViewEx : NTreeViewEx
{
    public delegate bool MyItemDragDropEventHandler(object sender, NLightUIItemDragDropEventArgs e);
    public event MyItemDragDropEventHandler ItemAllowDrag;

    protected override void ApplyDragDrop(NLightUIItemDragDropEventArgs e)
    {
        if (ItemAllowDrag != null)
        {
            if (!ItemAllowDrag(this, e))
                return;
        }
        base.ApplyDragDrop(e);
    }
}

And then I attached 2 events to my control:

private bool TreeList_ItemAllowDrag(object sender, NLightUIItemDragDropEventArgs e)
{
    if (e.Item.Name == "FOLDER")
        return false;
    if (e.DragOverItem.Name == "COMPONENT")
        return false;
    return true;
}

private void TreeList_ItemDrag(object sender, NLightUIItemDragDropEventArgs e)
{
    NLightUIItem DragOverItem = TreeList.ItemFromPoint(e.MousePosition);
    if (e.Item.Name != "COMPONENT")
        e.Cursor = Cursors.No;
    else if (DragOverItem != null && DragOverItem.Name == "COMPONENT")
        e.Cursor = Cursors.No;
    else
        e.Cursor = null;
}


Is it possible to also avoid the node hover effect?

Thanks,
Juan


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