maazza maazza - 5 months ago 50
C# Question

Disable Drag & Drop based on a condition

I am trying to allow/disallow drag&drop on a treeview based on flag in a Tag object.
But I can't find the proper event for this (something like BeforeDrag).

I am using C# and winforms, thanks.


Ralf was right all I had to do was to add a check In the ItemDrag callback.

private void tree_ItemDrag(object sender, ItemDragEventArgs e)
    var node = (e.Item as TreeNode).Tag as DataObject;
       DoDragDrop(e.Item, DragDropEffects.Move);
        MessageBox.Show("Frozen nodes cannot be moved", "Drag & Drop error", 
                        MessageBoxButtons.OK, MessageBoxIcon.Error);