Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 100373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:34:02+00:00 2026-05-11T00:34:02+00:00

I need to receive the key press events during cell editing in DataGridView control.

  • 0

I need to receive the key press events during cell editing in DataGridView control.

From what I have found on the net the DataGridView is designed to pass all key events from DataGridView to the cell editing control and you cannot get these events easily.

I found this piece of code that traps those events for DataGrid control, but that does not work for DataGridView.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:34:03+00:00Added an answer on May 11, 2026 at 12:34 am

    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: keyPressHook.

    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;  } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I receive data files from a source I have no control over (the government)
The Problem: I need to receive different types of content from a number of
In order to send and receive encrypted messages from/to the iPhone I need to
I currently have designed a system for simple send message receive message using such
I have a IV (initialization vector) and key, also a cryptogram. I need do
I need to perform http PUT operations from python Which libraries have been proven
I need to make a Function that receives a Session Key and a Session
I am new to ruby. I need to receive password as an input through
I need to send and receive data over serial connections (RS-232 and RS-422). How
I need to be able to receive a fax in a java application. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.