开发者

windows form validation issues (.net2.0 )

开发者 https://www.devze.com 2023-04-08 12:49 出处:网络
I need help with some things regarding windows form validation: closing form using standard form closing button (X) triggers validation of all controls.

I need help with some things regarding windows form validation:

  1. closing form using standard form closing button (X) triggers validation of all controls. Is there a way to supress it when closing form using this button, and force it only when pressing my own button?
  2. validation of textbox (possibly other controls, I tested only textboxes) wont invoke when i change text (value) programatically. I need to type text directly into textbox if I want validation to be triggered later, before form is closed. How to tell the form that some control needs validation (but not to trigger it immedidately)?

Thanks.

EDIT: (1) solved, using this answer. (2) now, after i set AutoValidate property to false and added ValidateChildren() to my button, only 1 control is being validated with its current value, values of all other controls are revert to value binded to them from DataSource object . I checked it in Validating event - only first control validating keeps its current value, after this validation is finished, other cont开发者_开发知识库rols' values are replaced with values from DataSource object. I don't understand why. Any clues?


Try this, maybe it could help you. ( for 1)

In the Forms Load event you can put this.ControlBox = false;. This will hide your X button with the other buttons at the top. The Form has a Form1_FormClosing event. In that Event you could call the triggers you need. Put a button on the form, and in button_Click event you type this.Close().

0

精彩评论

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

关注公众号