以下代码拒绝在鼠标右键单击中进行拖放操作。当我右键单击鼠标时,我确实看到了正确的上下文菜单,但我无法拖放,尽管我有DragDrop,DragEnter和DragOver的事件处理程序。是因为我没有上下文菜单并拖放同一个右键单击?我究竟做错了什么?非常感激您的帮忙。
private void treeList1_MouseDown(object sender, MouseEventArgs e)
{
TreeList tree = sender as TreeList;
Point pt = tree.PointToClient(MousePosition);
TreeListHitInfo info = tree.CalcHitInfo(pt);
if (e.Button == MouseButtons.Right && ModifierKeys == Keys.None && tree.State == TreeListState.Regular)
{
if (nodeType == typeof(X))
{
tree.ContextMenuStrip = XContextMenu;
tree.FocusedNode = info.Node;
treeList1.AllowDrop = true;
tree.AllowDrop = true;
}
currentFocusNode = tree.FocusedNode;
return;
}
}
答案 0 :(得分:1)
您没有使用 DoDragDrop 方法。
以下是使用DragDrop的example
在您的示例中,在return;
treeList1.DoDragDrop(currentFocusNode, DragDropEffects.Copy);
答案 1 :(得分:1)
以下是如何在listView上执行dragDrop,例如:
private void Form1_Load(object sender, EventArgs e)
{
listView1.AllowDrop = true;
listView1.DragDrop += new DragEventHandler(listView1_DragDrop);
listView1.DragEnter += new DragEventHandler(listView1_DragEnter);
}
void listView1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
void listView1_DragDrop(object sender, DragEventArgs e)
{
listView1.Items.Add(e.Data.ToString());
}