maazza maazza - 1 year ago 109
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.

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download