I figured out how to drag rows between datagridviews from how to drag gridview row from one grid to another, but now I have a problem. I can drag the row from gridPODetails to DataGridView1. I can drag the row back to gridPODetails from DataGridView1. But after that I get nothing. I would expect to be able to drag back and forth indefinately, but I can only go there and back. What could be causing this and how to correct?
private void gridPODetails_MouseDown(object sender, MouseEventArgs e)
{
DataGridView.HitTestInfo info = gridPODetails.HitTest(e.X, e.Y);
if (info.RowIndex >= 0)
{
DataRow view = ((DataTable)(gridPODetails.DataSource)).Rows[info.RowIndex];
if (view != null)
{
gridPODetails.DoDragDrop(view, DragDropEffects.Copy);
}
}
}
private void gridPODetails_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void gridPODetails_DragDrop(object sender, DragEventArgs e)
{
DataGridView grid = sender as DataGridView;
DataTable table = grid.DataSource as DataTable;
DataRow row = e.Data.GetData(typeof(DataRow)) as DataRow;
if (row != null && table != null && row.Table != table)
{
table.ImportRow(row);
row.Delete();
}
}
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
DataGridView.HitTestInfo info = dataGridView1.HitTest(e.X, e.Y);
if (info.RowIndex >= 0)
{
DataRow view = ((DataTable)(dataGridView1.DataSource)).Rows[info.RowIndex];
if (view != null)
{
dataGridView1.DoDragDrop(view, DragDropEffects.Copy);
}
}
}
private void dataGridView1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
DataGridView grid = sender as DataGridView;
DataTable table = grid.DataSource as DataTable;
DataRow row = e.Data.GetData(typeof(DataRow)) as DataRow;
if (row != null && table != null && row.Table != table)
{
table.ImportRow(row);
row.Delete();
}
}
table.AcceptChangesmight help things