0
votes

I'm creating a custom Editing Control for a DataGridView which is based on TextBox. This works fine, except for the fact that (although I can override the OnValidating event) setting e.Cancel to true won't prevent the user from leaving the cell.

How can I force to stay in the editing control when user enters invalid data?

This must be possible, because when you enter invalid data in a bound column you have to implement Dataerror event and user is not able to leave cell while data is invalid.

1

1 Answers

1
votes

I solved it by overriding the OnValidating event of the EditingControl to skip base.OnValidating. Added code in CellValidating of Grid which calls a custom Validation method of the underlying Editing Control, setting e.Cancel = true when validation fails.