c#-从一个树视图拖放到另一个树视图-WinForms
我的TreeView(treeV和treeV_忽略)都有如下DragAndDrop事件: 这些树视图是从Oracle数据集填充的,表示相同的数据 我希望能够从“treeV”中拖动一个项目,并将其放到“treeV_忽略”中c#-从一个树视图拖放到另一个树视图-WinForms,c#,winforms,treeview,C#,Winforms,Treeview,我的TreeView(treeV和treeV_忽略)都有如下DragAndDrop事件: 这些树视图是从Oracle数据集填充的,表示相同的数据 我希望能够从“treeV”中拖动一个项目,并将其放到“treeV_忽略”中 我如何才能实现这种行为?您的要求已经完全满足了 请调查。 此外,您必须首先了解,这里的SplitContainer用于拖放目的,我们可以将treeview添加到此控件,以便轻松地将任何节点拖动到另一棵树。如果您有任何问题,请告诉我您已经做了什么?您是否使用了推荐的ItemDra
我如何才能实现这种行为?您的要求已经完全满足了
请调查。
此外,您必须首先了解,这里的
SplitContainer
用于拖放目的,我们可以将treeview添加到此控件,以便轻松地将任何节点拖动到另一棵树。如果您有任何问题,请告诉我您已经做了什么?您是否使用了推荐的ItemDrag事件??发生了什么?@user6002727我上面的代码有问题。我已经确定了放置位置在“treeV”(尝试从“treeV_忽略”-上面的事件所在位置到“treeV”)。即使如此,它也不起作用,为什么我将鼠标移到另一棵树上查看它不允许掉落,所以我显然遗漏了一些重要的内容。@TaW我不确定我是否理解你的问题。我已经实现了所有这些事件。其中一个有:DoDragDrop(e.Item,DragDropEffects.move);您一开始没有显示它们。-嗯,当您尝试时会发生什么?另外:在测试鼠标事件时不要使用MessageBox!使用Console.WriteLine,这样您就不会弄乱焦点等。。
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;
}