2010-06-26 95 views
0

当我将拖放&拖放到DataGridView之后,CellDoubleClick事件停止工作。在CellMouseDown事件中,我有以下代码:添加拖放之后,CellDoubleClick事件不起作用

private void dataGridView2_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) 
{ 
    var obj = dataGridView2.CurrentRow.DataBoundItem; 
    DoDragDrop(obj, DragDropEffects.Link); 
} 

如何纠正这种使CellDoubleClick事件?

回答

2

是的,这是行不通的。调用DoDragDrop()将鼠标控制转换为Windows D + D逻辑,这将干扰正常的鼠标处理。您需要延迟启动D + D,直到您看到用户实际拖动为止。这应该解决问题:

Point dragStart; 

    private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { 
     if (e.Button == MouseButtons.Left) dragStart = e.Location; 
    } 

    private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e) { 
     if (e.Button == MouseButtons.Left) { 
      var min = SystemInformation.DoubleClickSize; 
      if (Math.Abs(e.X - dragStart.X) >= min.Width || 
       Math.Abs(e.Y - dragStart.Y) >= min.Height) { 
       // Call DoDragDrop 
       //... 
      } 
     } 
    } 
+0

Thanks!这很好。 – Max 2010-06-26 15:38:15