Click here to Skip to main content
15,943,077 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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("Age", typeof(double));
dt.Rows.Add("John Doe",30);
dt.Rows.Add("Jane Doe",31);

grid1.DataSource = dt;

Form frm2 = new Form();
DataGridView grid2 = new DataGridView();
grid2.AllowDrop = true;
grid2.DragEnter += grid2_DragEnter;
grid2.DragDrop += grid2_DragDrop;


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);

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!
Updated 7-Apr-13 1:44am

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900