maazza
maazza

Reputation: 7193

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.

Upvotes: 2

Views: 2807

Answers (2)

maazza
maazza

Reputation: 7193

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;
    if(!node.IsFrozen)
       DoDragDrop(e.Item, DragDropEffects.Move);
    else
        MessageBox.Show("Frozen nodes cannot be moved", "Drag & Drop error", 
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
}

Upvotes: 4

Dolhescu Stefan
Dolhescu Stefan

Reputation: 21

Try something of the sorts in your drag function:

private void onMouseDownStartDrag(object sender,'insert other necessary parameters here')
{
 if (Convert.ToString(sender.tag == "true"));
     {
      //code that enables dragging the object
     }
}

Upvotes: 1

Related Questions