DragDrop不工作 [英] DragDrop Not Working

查看:78
本文介绍了DragDrop不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个C#winForm应用程序,它有两个带有dataGridView的winForm'。



我有一个网格启用从另一个接收数据,但它不起作用。如果我从另一个不属于我的项目的winForm拖动它可以工作。

I''m writing a C# winForm app that has two winForm''s with dataGridView''s.

I have one grid enable to receive data from the other but it''s not working. If I drag from another winForm that''s not part of my project it works.

Form frm1 = new Form();
DataGridView grid1 = new DataGridView();
grid1.MouseDown += grid1_MouseDown;

DataTable dt = new DataTable();
dt.Columns.Add("Name",typeof(string));
dt.Columns.Add("Age", typeof(double));
dt.Rows.Add("John Doe",30);
dt.Rows.Add("Jane Doe",31);

grid1.DataSource = dt;
frm1.Controls.Add(grid1);

Form frm2 = new Form();
DataGridView grid2 = new DataGridView();
grid2.AllowDrop = true;
grid2.Columns.Add("colName","Name");
grid2.Columns.Add("colAge","Age");
grid2.DragEnter += grid2_DragEnter;
grid2.DragDrop += grid2_DragDrop;

frm2.Controls.Add(grid2);

privte void grid1_MouseDown(object sender, EventArgs e)
{
     e.Effect = DragDropEffects.Copy;
}

private void grid2_DragEnter(object sender, DragEventArgs e)
{
   e.Effect = DragDropEffects.Copy;
}

private void grid2_DragDrop(object sender, DragEventArgs e)
{
    string name = (string) e.Data.GetData(typeof(string));
    grid2.Rows.Add(name, 30);
}



我无法从grid1拖放到grid2中!但是如果grid1与grid2不在同一个解决方案中,那么我可以拖放到grid2中。这里发生了什么。 Windows API变得非常烦人!


I CAN NOT drag and drop from grid1 into grid2! BUT if grid1 IS NOT in the same solution as grid2 I can then drag and drop into grid2. what''s going on here. windows API is becoming VERY annoying!

推荐答案

请阅读以下文章:

我怎样才能将DataGridView行拖放到彼此之下? [ ^ ]

拖动&安培; drop to DataGridView? [ ^ ]

如何提供文件拖放 - 和Visual C#应用程序中的-drop功能 [ ^ ]

拖放概述 [ ^ ]

执行拖放操作 [ ^ ]

在Visual Basic .NET中实现拖放 [ ^ ]

演练:在Windows窗体中执行拖放操作 [如何:使用Windows窗体RichTextBox控件启用拖放操作 [ ^ ]
Please, read below articles:
How could I Drag and Drop DataGridView Rows under each other?[^]
Drag & drop to DataGridView?[^]
How to provide file drag-and-drop functionality in a Visual C# application[^]
Drag and Drop Overview[^]
Performing Drag-and-Drop Operations[^]
Implementing Drag and Drop in Visual Basic .NET[^]
Walkthrough: Performing a Drag-and-Drop Operation in Windows Forms[^]
How to: Enable Drag-and-Drop Operations with the Windows Forms RichTextBox Control[^]


这篇关于DragDrop不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆