本文介绍了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!

推荐答案


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

10-11 23:05