Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# WinForm
vs2008 + datagridview + cellvalidating event not fire....while change the value of particular cell.

any Help!!!
Posted 17-Oct-12 0:45am
Edited 17-Oct-12 9:29am
Pete O'Hanlon at 17-Oct-12 6:05am
This event only fires when the cell loses focus. Are you sure that focus has been lost?
Member 9444634 at 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 at 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.

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

Advertise | Privacy | Mobile
Web04 | 2.8.150326.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2015
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