【问题标题】:CellDoubleClick event doesnt work after addition of Drag&Drop添加拖放后 CellDoubleClicked 事件不起作用
【发布时间】:2011-03-08 15:15:13
【问题描述】:

在向 DataGridView 添加拖放操作后,CellDoubleClick 事件停止工作。在 CellMouseDown 事件中,我有以下代码:

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

如何更正此问题以启用 CellDoubleClick 事件?

【问题讨论】:

    标签: c# winforms events drag-and-drop


    【解决方案1】:

    是的,这行不通。调用 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
                    //...
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-29
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多