[英]How can I drag a folder from my Windows Explorer into a ListView and load the files into it?
I can't seem to make this work using this: 我似乎无法使用此工作:
private void listView1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
}
private void listView1_DragDrop(object sender, DragEventArgs e)
{
string[] directoryName = (string[])e.Data.GetData(DataFormats.FileDrop);
string[] files = Directory.GetFiles(directoryName[0]);
foreach (string file in files)
{
if (Path.GetExtension(file) == ".mp3")
{
listView1.Items.Add(file);
}
}
}
The mouse cursor shows a NOT sign and I can't drop the folder in my program. 鼠标光标显示一个NOT符号,并且我无法将文件夹拖放到程序中。
Have you set the AllowDrop
property of your ListView
to True? 您是否已将
ListView
的AllowDrop
属性设置为True?
Is your DragEnter
event ever being hit? 您的
DragEnter
事件是否曾经被击中?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.