简体   繁体   English

如何将文件夹从Windows资源管理器拖到ListView并将文件加载到其中?

[英]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? 您是否已将ListViewAllowDrop属性设置为True?

Is your DragEnter event ever being hit? 您的DragEnter事件是否曾经被击中?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将文件从ListView拖放到Windows资源管理器? - Drag & Drop file from listview to windows explorer? 如何在 Windows 资源管理器中打开文件夹? - How can I open a folder in Windows Explorer? 如何在C#中将文件夹/文件从一个Windows资源管理器拖放到另一个Windows资源管理器? - How to drag and drop folders/files from One Windows Explorer to another windows explorer in C#? 如何允许从Windows资源管理器拖放到C#WPF应用程序中? - How can I allow Drag and Drop from Windows Explorer into a C# WPF application? 无法将文件从WPF ListView拖动到Windows资源管理器 - Unable to drag file to Windows Explorer from a WPF ListView 如何将文件夹文件加载到ListView中? - How can I load a folders files into a ListView? 将文件夹从Windows资源管理器拖放到C#中的listBox - Drag and Drop a Folder from Windows Explorer to listBox in C# WPF将文件从Windows资源管理器拖放到TreeView上 - WPF drag and drop files onto TreeView from windows explorer 将文件拖放到 wpf/C# 应用程序时,如何在 Windows 资源管理器中维护文件顺序? - How do I maintain the file order in Windows Explorer when drag and dropping files into wpf/C# application? 将大型虚拟文件从 C# 拖放到 Windows 资源管理器 - Drag and drop large virtual files from C# to Windows Explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM