无法将拖放文件拖到datagridview

时间:2015-05-27 13:20:55

标签: c# winforms datagridview

所以我做了一个应用程序,现在我想实现拖放功能。 现在,当它在窗体中的任何地方工作时,当我尝试在datagridview上拖动它时,我会得到“取消”图标。

我已将datagridview allowdrop属性设置为true,订阅了拖动事件。 Datagrid是可见的并且已启用。

这可能是它的容器问题(splitcontainer-> tabcontrol - > tabpage,但到目前为止,我通过设置所有容器属性allowdrop = true没有任何区别)?我错过了什么?

@EDIT事件的代码。虽然无济于事。

void Form1_DragDrop(object sender, DragEventArgs e)
    {
        string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
        if (files.Count() == 1)
        {
            if (System.IO.File.Exists(files[0]) && files[0].Substring(files[0].LastIndexOf('.') + 1).ToLower().Contains("xls"))
            {
                loadExcel(files[0]);

            }
        }
    }
void Form1_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
    }

void DGW_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.Text)) e.Effect = DragDropEffects.Copy;
    }
void DGW_DragDrop(object sender, DragEventArgs e)
    {
            string head = (string)e.Data.GetData(DataFormats.Text);
            //the same follow up code  as in the form1_dragdrop 
    }

0 个答案:

没有答案
相关问题