Toolstripbutton not validating textbox.
-
I have a textbox, a standard button and a toolstrip containing a couple of buttons. In the validating event of the textbox i coded to check whether it is blank. If yes then it shows a message 'Enter Value'. When the standard button is clicked while the textbox is empty, it's validating properly and showing the message but when the toolstripbutton is clicked it's not not validating the textbox and no message is being shown. It seems that I gotto write the validation code explicitly in the toolstripbutton_click event which is too troublesome when there are multiple textboxes and toolstripbuttons on a single form. What I want to know is whether the textbox_validating can be fired while the toolstripbutton is clicked? Handling toolstrips is really a headache. Please help. I'm badly in need of it. Regards.
-
I have a textbox, a standard button and a toolstrip containing a couple of buttons. In the validating event of the textbox i coded to check whether it is blank. If yes then it shows a message 'Enter Value'. When the standard button is clicked while the textbox is empty, it's validating properly and showing the message but when the toolstripbutton is clicked it's not not validating the textbox and no message is being shown. It seems that I gotto write the validation code explicitly in the toolstripbutton_click event which is too troublesome when there are multiple textboxes and toolstripbuttons on a single form. What I want to know is whether the textbox_validating can be fired while the toolstripbutton is clicked? Handling toolstrips is really a headache. Please help. I'm badly in need of it. Regards.
This is an undocumented feature and appears to be by design. (don't you just hate that terminology) I guess it makes sense in a non-OOP way. When an event in the ToolStrip is raised, the control within the form that has focus, does not lose that focus! Therefore the validated/validating events of the control that has focus, are not raised. The approach I take is to refactor each validation and provide a method that calls all validations within a single method. It's nice to provide control by control validation but there is no guarantee that a control will ever gain or lose focus. You need an overall validation method to handle this. If your dealing with an underlying data source you may also want to look at the IDataErrorInfo interface.
-
I have a textbox, a standard button and a toolstrip containing a couple of buttons. In the validating event of the textbox i coded to check whether it is blank. If yes then it shows a message 'Enter Value'. When the standard button is clicked while the textbox is empty, it's validating properly and showing the message but when the toolstripbutton is clicked it's not not validating the textbox and no message is being shown. It seems that I gotto write the validation code explicitly in the toolstripbutton_click event which is too troublesome when there are multiple textboxes and toolstripbuttons on a single form. What I want to know is whether the textbox_validating can be fired while the toolstripbutton is clicked? Handling toolstrips is really a headache. Please help. I'm badly in need of it. Regards.
priyamtheone wrote:
Please help. I'm badly in need of it
Oh! your question will be more clear when you mention your code so please mention it. whatever, you can create a function and call it as many time you want to perform it. you don't need to create command every time for same work.
-
priyamtheone wrote:
Please help. I'm badly in need of it
Oh! your question will be more clear when you mention your code so please mention it. whatever, you can create a function and call it as many time you want to perform it. you don't need to create command every time for same work.
Well, calling common functionalities using methods is well known to everyone. That's not my question. What I asked for is whether textbox or other standard controls can be validated while toolstripbutton is clicked? As I learned gradually that toolstrip is not a control but a component and toolstripitems don't have CausesValidation property to cause them to validate any standard control on a form.
-
Well, calling common functionalities using methods is well known to everyone. That's not my question. What I asked for is whether textbox or other standard controls can be validated while toolstripbutton is clicked? As I learned gradually that toolstrip is not a control but a component and toolstripitems don't have CausesValidation property to cause them to validate any standard control on a form.