根据条件禁用拖放
Disable Drag & Drop based on a condition
我正在尝试 allow/disallow 根据 Tag 对象中的标志在树视图上拖放。
但是我找不到合适的事件(比如 BeforeDrag)。
我正在使用 C# 和 winforms,谢谢。
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);
}
在你的拖动功能中尝试一些这样的东西:
private void onMouseDownStartDrag(object sender,'insert other necessary parameters here')
{
if (Convert.ToString(sender.tag == "true"));
{
//code that enables dragging the object
}
}
我正在尝试 allow/disallow 根据 Tag 对象中的标志在树视图上拖放。 但是我找不到合适的事件(比如 BeforeDrag)。
我正在使用 C# 和 winforms,谢谢。
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);
}
在你的拖动功能中尝试一些这样的东西:
private void onMouseDownStartDrag(object sender,'insert other necessary parameters here')
{
if (Convert.ToString(sender.tag == "true"));
{
//code that enables dragging the object
}
}