防止双击行分隔符触发celldoubleclick事件

时间:2009-12-11 18:49:20

标签: winforms datagridview

在将rowheaders visibility设置为false并且allowusertoresizerow设置为true的datagridview中,我需要阻止celldoubleclick事件在rowdivider上双击时触发(当光标在分隔符上时,行调整大小的Toublearrow是可见的)。 / p>

由于

1 个答案:

答案 0 :(得分:4)

我想最简单的方法是检查CellDoubleClick事件本身的网格点击区域;如果没有点击rowresizetop或rowresizebottom区域,则返回逻辑,如果没有则继续处理。请查看以下示例以获取更多详细信息:

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
    // get mouse coordinates
    Point mousePoint = dataGridView1.PointToClient(Cursor.Position);
    DataGridView.HitTestInfo hitTestInfo = dataGridView1.HitTest(mousePoint.X, mousePoint.Y);
    // need to use reflection here to get access to the typeInternal field value which is declared as internal
    FieldInfo fieldInfo = hitTestInfo.GetType().GetField("typeInternal", 
        BindingFlags.Instance | BindingFlags.NonPublic);
    string value = fieldInfo.GetValue(hitTestInfo).ToString();
    if (value.Equals("RowResizeTop") || value.Equals("RowResizeBottom"))
    {
        // one of resize areas is double clicked; stop processing here      
        return;
    }
    else
    {
        // continue normal processing of the cell double click event
    }
} 

希望这有帮助,尊重