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.
Thank you for providing me with better example of what you meant initially. In fact, I was expecting this event to be raised, even the validation of the TextBox is canceled, but then I have made a further investigation and it seems that you are right. AfterSelect event should not be raised on the UltraTree, once TextBox’s validation is canceled. This is clearly a bug in our control.
Therefore I have logged this behavior in our internal tracking system with development id number of 208324 and the next step will be a developer to review my investigation, confirm that it is actually a bug and propose appropriate fix.
There is an associated ticket linked to your account about this forum thread, where you can follow the progress of this resolution.
As a workaround of this issue, you can use Tree’s EventManager object. It allows you to temporarily enable or disable specific event or group of events. There is a code snippet in our documentation here: http://help.infragistics.com/Help/Doc/WinForms/2012.2/CLR4.0/html/Win_Event_Managers.html
Hi Ivaylo,
maybe I wasn't really clear what I meant, but I adjusted your project to see what my problem/confusion is. I replaced the messagebox with some Debug.Writelines
1) enable the chackbox, which is canceling the validating event
2) type something into the textbox
3) click on the ultratree (left tree) -> after select event is raised
4) click on the treeView (right tree) -> after select event is not raised
You will see, that the treeView does not fire the AfterSelect event (which I am expecting), but the ultratree is raising this event. I would normally expect, that ultratree should behave same. Did I miss something?
Although ToolbarsManager’s toolbar is not a control itself and neither is any built in tool that can be placed inside it, most of Infragistics controls derives from Microsoft’s System.Windows.Forms.Control class. This is the reason, why you can’t find CausesValidaiton property inside them. In case you want to place custom control as a tool inside a toolbar, you can change tool’s type to ControlContainer and associate it with whatever control you want.
Following your requirement, I placed two custom controls along with TextBox and UltraTree on a form. Then I subscribed and canceled the validation of the TextBox and on selecting a node I popped up a message that UltraTree’s AfterSelect event is raised. In fact AfterSelect event does raise and it works flawlessly.
You can find attached sample on the bottom of my post. Please take a look at the code behind, run it and give me a feedback how it behaves on your machine. I am waiting for your feedback.