开发者

In Winforms, why is validation not being fired after leaving TextBox and entering a DataGridView?

开发者 https://www.devze.com 2023-04-13 06:10 出处:网络
I\'m overriding the OnValidating event in a custom Winforms text box.I\'m finding that if the text box (which is bound to an object) has focus and then I give a grid focus using the mouse, the OnValid

I'm overriding the OnValidating event in a custom Winforms text box. I'm finding that if the text box (which is bound to an object) has focus and then I give a grid focus using the mouse, the OnValidating event doesn't always get fired. When I first give the grid focus, it gets fired fine. But, if put one of the grid's cell in edit (blinking cursor), from there on out it seems to not get fired when I go ba开发者_运维技巧ck between the text box and grid using the mouse. If I change focus using the tab key, the validating always gets fired. If I give focus to a non-grid control using the mouse, the validation is always getting fired.

I tried to recreate this functionality from scratch in a simple form and I can't recreate the problem. The grid I'm using in the setup where I'm getting the problem is a custom DataGridView with custom column types. I'm wondering if the grid is the problem. But, I don't see how it could affect the text box events. Any ideas?


It probably has to do with the CausesValidation property.

A control's validation is suppressed if focus is going to a control that has CausesValidation set to false. It's just a wild guess, but I'm thinking some control inside the grid has CausesValidation = false;

This property is meant for things like "Cancel" buttons, but can cause lots of confusion.

0

精彩评论

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