拖放列表视图中的C# [英] Drag and drop in listview C#
问题描述
您好,我目前正试图让我的程序能够拖动文件,并将其拖放到列表视图。我看到很多样品,其中大部分有以下code
私人无效listView1_draganddrop(对象发件人,DragEventArgs五)
hi i currently trying to have my program able to drag a file and and drop it into the listview. I have see many sample and most of them have the following code "private void listView1_draganddrop(object sender, DragEventArgs e)"
在我implmeneted那些code我有为数不多的错误我encounter..first是
无过载listview1_SelectedIndexChanged匹配委托系统的事件处理程序
however after i implmeneted those code i have the few error i encounter..first is the no overload for listview1_SelectedIndexChanged match delegate System event handler
和另一个概率是后code为implmeneted我不能拖动任何文件到列表视图
and another prob is the after the code is implmeneted i cannot drag any file into the listview
我已经让我的listview.so的允许压降我想知道我是怎么缺乏,使阻力,在C#中拖放功能,以及如何我code中的拖放
i have enable the allow drop on my listview.so i was wondering what did i lack of to enable drag and drop function in c# and how to i code the drag and drop
推荐答案
相同的答案我在这里提供:的拖放的ListView C#
Same answer I provided here: Drag and drop listview C#
您需要执行的dragenter 事件并设置DragEventArgs效应财产。在的dragenter 活动是允许的事情被投进控制。之后,在的DragDrop 鼠标按钮被释放时事件将触发。
You need to implement the DragEnter event and set the Effect property of the DragEventArgs. The DragEnter event is what allows things to be dropped into a control. After that the DragDrop event will fire when the mouse button is released.
下面是一个版本,将允许物体投进一个ListView:
Here is a version that will allow objects to be dropped into the a ListView:
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());
}
这篇关于拖放列表视图中的C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!