2009-12-11 37 views

回答

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 
    } 
} 

希望這會有所幫助,至於

+0

謝謝你,你的代碼工作得很好。 –

+0

由於完全不同的原因,我還需要知道我是否單擊了datagridview行的調整大小區域。這工作完美 - 謝謝! – neminem

+0

謝謝!爲什麼Microsoft不能在DataGridViewHitTestType枚舉中包含行和列分隔符的值? – alldayremix