然后在treeview 的 DragEnter 中接收拖放。
最后在treeview的 DragDrop 中处理拖放结果。
注:treeview的 AllowDrop 属性要设置为 true。
[复制到剪贴板] |
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
DataGridView.HitTestInfo info = dataGridView1.HitTest(e.X, e.Y);
if (info.RowIndex >= 0)
{
DataGridViewRow dr = (DataGridViewRow)
dataGridView1.Rows[info.RowIndex];
if (dr != null)
dataGridView1.DoDragDrop(dr, DragDropEffects.Copy);
}
}
}
private void treeView1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void treeView1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(DataGridViewRow)))
{
Point p = treeView1.PointToClient(new Point(e.X, e.Y));
TreeViewHitTestInfo index = treeView1.HitTest(p);
if (index.Node != null)
{
DataGridViewRow drv = (DataGridViewRow)e.Data.GetData(typeof(DataGridViewRow));
index.Node.Text = "Drop: " + drv.Cells[0].ToString();
}
}
}