Winforms 防止双击行分隔符触发DoubleClick事件
在rowheaders可见性设置为false且allowusertoresizerow设置为true的datagridview中,如果双击行分隔符,我需要防止触发celldoubleclick事件(当光标位于分隔符上时,行大小调整的ToubleRow可见)Winforms 防止双击行分隔符触发DoubleClick事件,winforms,datagridview,Winforms,Datagridview,在rowheaders可见性设置为false且allowusertoresizerow设置为true的datagridview中,如果双击行分隔符,我需要防止触发celldoubleclick事件(当光标位于分隔符上时,行大小调整的ToubleRow可见) 谢谢我想最简单的方法是在CellDoubleClick事件本身上检查网格的点击区域;逻辑是在单击rowresizetop或rowresizebottom区域时返回,如果没有,则继续处理。有关更多详细信息,请查看以下示例: private vo
谢谢我想最简单的方法是在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
}
}
希望这能有所帮助,关于我想最简单的方法是在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
}
}
希望这能有所帮助,因为出于完全不同的原因,我还需要知道我是否在单击datagridview行的调整大小区域。这非常有效-谢谢!非常感谢。为什么Microsoft不能在DataGridViewHitTestType枚举中包含行和列分隔符的值?出于完全不同的原因,我还需要知道是否单击了datagridview行的调整大小区域。这非常有效-谢谢!非常感谢。为什么Microsoft不能在DataGridViewHitTestType枚举中包含行和列分隔符的值?