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

any Help!!!
Posted 16-Oct-12 23:45pm
Edited 17-Oct-12 8:29am
v4
Comments
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
good
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.
  Permalink  

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

  Print Answers RSS
0 Maciej Los 225
1 OriginalGriff 205
2 Manfred R. Bihy 190
3 CHill60 180
4 Sergey Alexandrovich Kryukov 164
0 OriginalGriff 7,395
1 Sergey Alexandrovich Kryukov 6,163
2 Maciej Los 3,754
3 Peter Leow 3,448
4 CHill60 2,702


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2014
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