![]() I really don't see this as an ideal approach. I default everything to not CauseValidation, enables them all before I use the event for validating the whole form, and disables them all after again. So basic question is, what is the best approach to validate a specific set of controls only when I want to and not when focus is lost from the control?ĮDIT: presently as a work around, I have a method that toggles the "CausesValidation" property on and off. ![]() I have been using the ErrorProvider class to support this visually. They use "e.Cancel = true " to cancel the validation. However, I don't want to have the validation run when the textboxes lose focus, only when the whole form is being validated.Įach control that I want to be validated, I have registered with the "validating" event. I only want to close the form if the validation is successful. MessageBox.Show("Validation passed with flying colours. So I have an event that fires for that like so: if (!this.ValidateChildren()) However, I only want this validation to occur when I click a button. I have a C# winform project that I want to validate a form before closing. The third class I've included is TextBo圎rrorDisplayStrategy.I'm fairly new to using validation. When it needs to display an error for a given WPF control, it will consult this list, looking for a strategy that will work on the given element. When you add the ErrorProvider to your form, it maintains a list of IErrorDisplayStrategy objects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |