【问题标题】:Disable Drag & Drop based on a condition根据条件禁用拖放
【发布时间】:2015-07-23 07:54:58
【问题描述】:

我正在尝试根据标记对象中的标志在树视图上允许/禁止拖放。 但我找不到合适的事件(比如 BeforeDrag)。

我正在使用 C# 和 winforms,谢谢。

【问题讨论】:

  • 你认为你为什么需要一个活动?仅在满足您的条件时调用 DoDragDrop 方法。与删除相同,只需在执行任何操作之前检查拖动事件中的条件。

标签: c# winforms drag-and-drop treeview


【解决方案1】:

Ralf 是对的,我所要做的就是在 ItemDrag 回调中添加一个检查。

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);
}

【讨论】:

    【解决方案2】:

    在你的拖动功能中尝试一些东西:

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

    【讨论】:

      猜你喜欢
      • 2015-10-09
      • 1970-01-01
      • 2021-01-06
      • 2019-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      相关资源
      最近更新 更多