开发者

Validating custom Editing Control in DataGridView

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开发者_StackOverflow 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜