0
在rowheaders可見性設置爲false且allowusertoresizer設置爲true的datagridview中,如果雙擊rowdivider,我需要防止celldoubleclick事件觸發(行resize的Toublearrow可見當光標在分隔線上時)。防止雙擊觸發celldoubleclick事件的行分隔線
感謝
在rowheaders可見性設置爲false且allowusertoresizer設置爲true的datagridview中,如果雙擊rowdivider,我需要防止celldoubleclick事件觸發(行resize的Toublearrow可見當光標在分隔線上時)。防止雙擊觸發celldoubleclick事件的行分隔線
感謝
我想最簡單的方法是檢查在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行的調整大小區域。這工作完美 - 謝謝! – neminem
謝謝!爲什麼Microsoft不能在DataGridViewHitTestType枚舉中包含行和列分隔符的值? – alldayremix