添加拖放后 CellDoubleClick 事件不起作用

CellDoubleClick event doesnt work after addition of Dragamp;Drop(添加拖放后 CellDoubleClick 事件不起作用)
本文介绍了添加拖放后 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+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 事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)