【发布时间】:2016-09-06 08:05:46
【问题描述】:
我的两个树视图(treeV 和 treeV_IgnoreD)都有如下 DragAndDrop 事件:
private void treeV_IgnoredDragDropEvent(object sender, DragEventArgs e)
{
// Retrieve the client coordinates of the drop location.
Point targetPoint = treeV_Ignored.PointToClient(new Point(e.X, e.Y));
// Retrieve the node at the drop location.
TreeNode targetNode = treeV.GetNodeAt(targetPoint);
// Retrieve the node that was dragged.
TreeNode draggedNode = (TreeNode)e.Data.GetData(typeof(TreeNode));
// Confirm that the node at the drop location is not
// the dragged node and that target node isn't null
// (for example if you drag outside the control)
if (!draggedNode.Equals(targetNode) && targetNode != null)
{
// Remove the node from its current
// location and add it to the node at the drop location.
draggedNode.Remove();
targetNode.Nodes.Add(draggedNode);
// Expand the node at the location
// to show the dropped node.
targetNode.Expand();
}
}
private void treeV_Ignored_ItemDrag(object sender, ItemDragEventArgs e)
{
DoDragDrop(e.Item, DragDropEffects.Move);
MessageBox.Show("ola");
}
private void treeV_Ignored_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
这些树视图是从 Oracle 数据集填充的,代表相同的数据。
我希望能够从“treeV”中拖动一个项目,并将其放在“treeV_Ignored”中。
我怎样才能实现这种行为?
【问题讨论】:
-
你做了什么?
-
你使用推荐的ItemDrag事件了吗??会发生什么?
-
@user6002727 我在上面的代码中遇到了问题。我已经将放置位置放在“treeV”上(试图从“treeV_Ignored” - 上面的事件所在的位置到“treeV”)。即便如此,它也不起作用,为什么我将鼠标移到另一个树视图上它不允许掉落,所以我显然错过了一些重要的东西。
-
@TaW 我不确定我是否理解您的问题。我已经实现了所有这些事件。那个有:DoDragDrop(e.Item, DragDropEffects.Move);
-
你一开始没有给他们看。 - 那么,当你尝试它时会发生什么?另外:测试鼠标事件时不要使用 MessageBox!使用 Console.WriteLine,这样你就不会弄乱焦点等。