Datagridview Cell Validating Problem

I have a cell Validating sub defined for a datagridview where if a cell did not meet some requirements, I set the errortext and prevent the user from moving by having the code e.cancel = true. The reason I have a cell validating defined is because if there is an error there is another grid which I don't user to click on until the error is fixed. The e.cancel = true works fine as soon as I click tab or leave the cell. The e.cancel = true doesn't work when I am still in the cell. what I can do to prevent this. Thanks.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Ajay SharmaConnect With a Mentor Commented:
i think u want validation on the textchange of cell.

What sort of validation u want ?

Suppose if u want ony numeric or text ten it is possibel. If u want a range then it will be complicated because the event will be fired befor the user completes enrty.
As the docs say, the CellValidating event [EMPHASIS added] "OCCURS WHEN A CELL LOSES INPUT FOCUS, enabling content validation."  What is cancelled by e.Cancel = True is the (attempted) move out of the cell.  So that it does not work "when I am still in the cell" is by design.  There is no attempted move out of the cell that can be cancelled.

If you want to validate while the user is still in the cell - that is, still entering/editing its contents - then you will need to use some other event or approach: perhaps, as ajaysharmaapjs suggests, working at the level of the keypress to the editing version of the cell.

That gets complicated.  I just wonder why you want to work with a different validating model than that which is native to the DataGridView.

All Courses

From novice to tech pro — start learning today.