C# 添加拖放后,CellDoubleClick事件不起作用;滴
在我将拖放添加到DataGridView后,CellDoubleClick事件停止工作。在CellMouseDown事件中,我有以下代码:C# 添加拖放后,CellDoubleClick事件不起作用;滴,c#,winforms,events,drag-and-drop,C#,Winforms,Events,Drag And Drop,在我将拖放添加到DataGridView后,CellDoubleClick事件停止工作。在CellMouseDown事件中,我有以下代码: private void dataGridView2_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { var obj = dataGridView2.CurrentRow.DataBoundItem; DoDragDrop(obj, DragDropEffect
private void dataGridView2_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
var obj = dataGridView2.CurrentRow.DataBoundItem;
DoDragDrop(obj, DragDropEffects.Link);
}
如何更正此错误以启用CellDoubleClick事件?是的,无法工作。调用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
//...
}
}
}