本文介绍了CellDoubleClick事件犯规此外拖&放后工作;降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我添加拖放放大器;下降到一个DataGridView,在CellDoubleClick事件停止工作。在CellMouseDown事件中,我有以下代码:

After I added drag & drop to a DataGridView, the CellDoubleClick event stopped working. In the CellMouseDown event I have the following code:

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



我如何纠正此使CellDoubleClick事件?

How do I correct this to enable CellDoubleClick event?

推荐答案

是的,这是行不通的。调用的DoDragDrop()打开鼠标控制到Windowsð+ D的逻辑,那将会有正常的鼠标处理干涉。您需要延迟开始为D + D直到看到用户实际拖动。这应该解决的问题:

Yes, that cannot work. Calling DoDragDrop() turns mouse control over to the Windows D+D logic, that's going to interfere with normal mouse handling. You need to delay starting the D+D until you see the user actually dragging. This ought to solve the problem:

    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
                //...
            }
        }
    }

这篇关于CellDoubleClick事件犯规此外拖&放后工作;降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 16:46