Mar*_*olo 0 datagridview winforms
在 rowheaders 可见性设置为 false 且 allowedusertoresizerow 设置为 true 的 datagridview 中,如果双击 rowdivider,我需要防止 celldoubleclick 事件触发(当光标位于分隔符上时,行调整大小的 Toublearrow 可见)。
谢谢
我想最简单的方法是检查 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
}
}
Run Code Online (Sandbox Code Playgroud)
希望这有帮助,问候