Hi,
I have a custom control on a form with textfields, where I do some validation by subscribing to the "textbox_validating" event.
But when I click on a tool item from the toolbarmanager (hosted in the form), the validating event of the textbox is not fired.
Thanks for help to understand this behaviour,
Michael
Hi Michael,
Thank you for posting in our forums!
In order to raise validating event of any control subscribed to it, you must either move its focus to another control or force it explicitly to be raised. As far as I understand you have a scenario where on clicking ToolbarsManager’s tool, custom control’s textbox validation should be raised.
All Windows Forms control containers implement two methods that force validating of one or all children controls. These methods are Validate and ValidateChildren. For further reference see MSDN’s documentation pages:
https://msdn.microsoft.com/en-us/library/4wf8t2at(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/ms158375(v=vs.110).aspx
Therefore you have to subscribe to ToolbarsManager ToolClick’s event and invoke custom control’s Validate method. This is going to raise the validating event only on the last control (text box) that was on focus.
Please let me know if you have any additional questions.
thanks for the quick answer.
So, the need of a manual validation is caused by the non-existing "CausesValidation" property of the toolbar or button? Normally the triggering of validation of controls is done by default. But ok, that makes sense when using a component control, not an user control.
Besides, I need some help/explanation with another issue:
I've created another form with two custom controls (one owning a textbox with validating event, one having an ultratree).
When I type something into the textbox and click on the ultratree, the validating event is raised (which I cancel) but then also the afterselect event is fired. This behaviour is not the same like with a normal treeview. Here the AfterSelect event is not raised, if I cancel the validating of the other control.