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 7036623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:26:47+00:00 2026-05-28T01:26:47+00:00

I need to perform a task whenever the user ordinarily ends edit mode (no

  • 0

I need to perform a task whenever the user ordinarily ends edit mode (no matter if the user actually modified the value or not; but not when the user cancels edit mode by pressing ESC) in a TextBox column of a DataGridView control.

I tried several events of the DataGridView control itself and also of the editing control, but none of them does exactly what I want:

DataGridView.CellValidating and DataGridView.CellValidated:

These events are fired whenever the user selects another cell, even if the cell was not in edit mode. I tried to check the IsCurrentCellDirty property inside the CellValidating event. This is almost what I need but IsCurrentCellDirty is only set when the user actually changes the value. But I also need to perform the task when the user ordinarily ends edit mode without having changed anything. These events are not fired when the user cancels edit mode, which is good.

DataGridView.CellValueChanged

This event is also fired too often (it is also fired when the value of a cell is set programmatically).

DataGridView.CellEndEdit

This event is almost what I want. But it is also fired when the user cancels edit mode by pressing ESC. Is there a way to check if edit mode was cancelled inside the CellEndEdit event?

DataGridView.CellParsing

This event is almost what I want. But it is not fired when the user ends edit mode without having changed anything.

Validating and Validated events of the editing control

I registered to these events inside the DataGridView.EditingControlShowing event. They do almost what I want but they are also fired when the user cancels edit mode by pressing ESC. Is there a way to check if edit mode was cancelled inside the these events?

Any other suggestions for events I could register to and/or flags I could check to achieve the desired behaviour?

  • 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. Editorial Team
    Editorial Team
    2026-05-28T01:26:47+00:00Added an answer on May 28, 2026 at 1:26 am

    What you can do is register to the PreviewKeyDown event of the EditingControl inside the EditingControlShowing event of the DataGridView. From there it is possible to detect if escape was pressed within the editing control, and set a flag that will be read by the CellEndEdit event.

    You can infer the necessary events to register from the method names. This assumes you have a bool field within your class named escapePressed which (not surprisingly) is the flag for escape being pressed.

    private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        e.Control.PreviewKeyDown -= Control_PreviewKeyDown; //avoid attaching multiple handlers in case control is cached
        e.Control.PreviewKeyDown += new PreviewKeyDownEventHandler(Control_PreviewKeyDown);
    }
    
    void Control_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
    {
        if (e.KeyCode == Keys.Escape)
        {
            Console.WriteLine("escape pressed");
            escapePressed = true;
        }
    }
    
    private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
        if (!escapePressed)
        {
            Console.WriteLine("do your stuff"); //escape was not pressed.
        }
        else escapePressed = false; //reset the flag
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery function already to perform the task I need but is
I'm new to audio analysis, but need to perform a (seemingly) simple task. I
I have a task I need to perform, do_stuff(opts) , that will take ~1s
In VIM, I need to perform a simple task - highlight ( and ).
I need to perform the following task : There are two 'ul' elements containing
I have a task that I need to perform for a friend as a
I have a simple task I need to perform in Python, which is to
I need to perform a a task when there are some values in my
I need to perform some background task periodically in CouchDB (guess that could be
I need to notify 1-many clients to perform a task (reload). The server may

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.