Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Finally figured out. There are two parts of this puzzle - getting keys from cell editing control and getting keys from the DataGridView itself. Here's my code. To use it, you just need to subscribe to the custom event: <strong>keyPressHook</strong>.</p> <pre><code>class KeyPressAwareDataGridView : DataGridView { protected override void OnControlAdded(ControlEventArgs e) { this.subscribeEvents(e.Control); base.OnControlAdded(e); } protected override void OnControlRemoved(ControlEventArgs e) { this.unsubscribeEvents(e.Control); base.OnControlRemoved(e); } protected override bool ProcessDataGridViewKey(KeyEventArgs e) { bool procesedInternally = false; if (this.keyPressHook != null) { this.keyPressHook(this, e); procesedInternally = e.SuppressKeyPress; } if (procesedInternally) { return true; } else { return base.ProcessDataGridViewKey(e); } } private void subscribeEvents(Control control) { control.KeyDown += new KeyEventHandler(this.control_KeyDown); control.ControlAdded += new ControlEventHandler(this.control_ControlAdded); control.ControlRemoved += new ControlEventHandler(this.control_ControlRemoved); foreach (Control innerControl in control.Controls) { this.subscribeEvents(innerControl); } } private void unsubscribeEvents(Control control) { control.KeyDown -= new KeyEventHandler(this.control_KeyDown); control.ControlAdded -= new ControlEventHandler(this.control_ControlAdded); control.ControlRemoved -= new ControlEventHandler(this.control_ControlRemoved); foreach (Control innerControl in control.Controls) { this.unsubscribeEvents(innerControl); } } private void control_ControlAdded(object sender, ControlEventArgs e) { this.subscribeEvents(e.Control); } private void control_ControlRemoved(object sender, ControlEventArgs e) { this.unsubscribeEvents(e.Control); } private void control_KeyDown(object sender, KeyEventArgs e) { if (this.keyPressHook != null) { this.keyPressHook(this, e); } } public event KeyEventHandler keyPressHook; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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