Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason that making an empty DoubleClick event method would not help would be that is executed in addition to the other operations that happen when a double click occurs.</p> <p>If you look at the windows generated code or examples of programatically adding event handlers, you use += to assign the event handler. This means you are adding that event handler in addition to the others that already exist, you could have multiple event handlers being triggered on the save event.</p> <p>My instinct would have been to override the DataGridView class, then override the OnDoubleClick method and not call the base OnDoubleClick method.</p> <p>However, I have tested this real quick and am seeing some interesting results.</p> <p>I put together the following test class:</p> <pre><code>using System; using System.Windows.Forms; namespace TestApp { class DGV : DataGridView { private string test = ""; protected override void OnDoubleClick(EventArgs e) { MessageBox.Show(test + "OnDoubleClick"); } protected override void OnCellMouseDoubleClick(System.Windows.Forms.DataGridViewCellMouseEventArgs e) { MessageBox.Show(test + "OnCellMouseDoubleClick"); } protected override void OnCellMouseClick(System.Windows.Forms.DataGridViewCellMouseEventArgs e) { if (e.Clicks == 1) { // Had to do this with a variable as using a MessageBox // here would block us from pulling off a double click test = "1 click "; base.OnCellMouseClick(e); } else { MessageBox.Show("OnCellMouseClick"); } } } } </code></pre> <p>Then inserted this into a windows form, adding a checkbox column and ran the program.</p> <p>On a fresh run, double clicking on the checkbox causes the messagebox display to say "1 click OnDoubleClick".</p> <p>This means that OnCellMouseClick executed on the first part of the double click and then OnDoubleClick executed on the second click.</p> <p>Also, unfortunately, the removal of the call to the base methods doesn't seem to be preventing the checkbox from getting the click passed to it.</p> <p>I suspect that for this approach to work it may have to be taken further and override the DataGridViewCheckBoxColumn and DataGridViewCheckBoxCell that ignores the double click. Assuming this works, you would be able to stop double click on the checkbox but allow it still on your other column controls.</p> <p>I have posted an answer on another question that talks about creating custom DataGridView columns and cells at <a href="https://stackoverflow.com/questions/121274/is-it-possible-to-bind-complex-type-properties-to-a-datagrid#128909">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload