Click here to Skip to main content
13,004,435 members (72,902 online)
Rate this:
Please Sign up or sign in to vote.
See more:

vs2008 + datagridview + cellvalidating event not fire....while change the value of particular cell.

any Help!!!
Posted 16-Oct-12 23:45pm
Updated 17-Oct-12 8:29am
Pete O'Hanlon 17-Oct-12 6:05am
This event only fires when the cell loses focus. Are you sure that focus has been lost?
Member 9444634 17-Oct-12 6:52am
oh i think its fire at value change,

leave it, i want to check for decimal value enter or not. Key Press event is not fire dont know wts d problem.
Member 9444634 17-Oct-12 6:54am
hello Arti you have any solution?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you want to validate data entry while still editing a cell you will need to set up a key press handler each time you begin editing a cell you need to validate.

To do that you must handle the DataGridview.EditingControlShowing event, and within that you will attach the keypress handler.

private void dataGridView1_EditingControlShowing(object sender,
    DataGridViewEditingControlShowingEventArgs e)
    dataGridView1.EditingControl.KeyPress -= new KeyPressEventHandler(MyKeyPressHandler);
    dataGridView1.EditingControl.KeyPress += new KeyPressEventHandler(MyKeyPressHandler);

By checking the arguments to the EditingControlShowing handler you can be selective about the cells you decide to validate, or use different key press handlers for each cell.
Note that the key press handler is removed before it is added. This is to prevent a build up of identical handlers when you keep entering a cell. Removing a handler which doesn't exist (on first entry) isn't a problem.
Jothimani N 16-May-16 14:22pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170627.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100