我添加了拖动&放到DataGridView,CellDoubleClick事件停止工作。在CellMouseDown事件中,我有以下代码:
private void dataGridView2_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
var obj = dataGridView2.CurrentRow.DataBoundItem;
DoDragDrop(obj, DragDropEffects.Link);
}
如何更正此功能以启用CellDoubleClick事件?
答案 0 :(得分: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
//...
}
}
}