Windows Develop Bookmark and Share   
 index > Windows Forms Designer > textbox.validating fires AFTER button.click event
 

textbox.validating fires AFTER button.click event

ok. this is one of the simplest things i ever tried and i failed miserably.

i've got a textbox that needs to be validated and a button embedded in a bindingnavigator that calls the addnew() method of a bindingsource.
now validation of the textbox _must_ occur before the bindingsource adds a new element to the underlying list, because if the textbox contains invalid text the bindingsource.addnew method must not be fired.

the current behavior (VS 2k8 SP1, .NET 3.5 SP1, C#) is that when the button is clicked, the bindingsource.addnew() fires before (!) the validation of the TextBox fires. the textbox.validating event eventually fires, but just too late.

any ideas?

TomTom1234  Thursday, March 05, 2009 10:04 AM
Bruce,

thank you very much for your answer. as this is part of a highly complex application i won't be able to provide an in-context example which shows/reproduces this behavior without posting huge parts of the source as well.
obviously, in a more simple scenario the events fire as expected. i kinda solved this behavior by disabling the button which in turn triggers the .addnew method and enable it during the validation. so far, this works for me. i still don't really know why -in my specific scenario- the .validating event fires too late.
TomTom1234  Wednesday, March 11, 2009 11:01 AM
http://www.codeproject.com/KB/miscctrl/validatingtextbox.aspx
Thanks, A.m.a.L
  • Proposed As Answer byKenky Dude Friday, March 06, 2009 5:57 AM
  • Unproposed As Answer byTomTom1234 Friday, March 06, 2009 6:21 AM
  • Proposed As Answer byvaldimerpenov Friday, March 06, 2009 7:03 AM
  •  
A.m.a.L - aditi.com - Think Product  Thursday, March 05, 2009 10:41 AM
*sigh* obviously you didn't even try to read my post. maybe i should have put in a "i'm not retarded" as the first line.

i DO know how to validate a control. i don't need a 7 year old custom textbox control as the .validating event does everything i need, if it would work as supposed.
my problem is that obviously due to some weird behavior the button's click event is placed in the message queue BEFORE the textbox.validating event.

anyone else?
TomTom1234  Thursday, March 05, 2009 10:50 AM
Hi TomTom1234,

The problem can't be reproduced on my side. The validating event of the TextBox is occuring before the AddingNew event.

I just Drag some field from the DataSource View. The Visual Studio designer generates the BindingSourceNavigator and TextBox and Label for me. Then I print a message in the Validating event handler of the TextBox and the AddingNew event handler of the BindingSource. It turns out that the validating event is fired first.

If you are in a differentscenario with me, please let me know.

Edit: I am in the same development enviroment with you.

Best regards,
Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Friday, March 06, 2009 1:33 PM
We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post editor window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Tuesday, March 10, 2009 6:58 AM
Bruce,

thank you very much for your answer. as this is part of a highly complex application i won't be able to provide an in-context example which shows/reproduces this behavior without posting huge parts of the source as well.
obviously, in a more simple scenario the events fire as expected. i kinda solved this behavior by disabling the button which in turn triggers the .addnew method and enable it during the validation. so far, this works for me. i still don't really know why -in my specific scenario- the .validating event fires too late.
TomTom1234  Wednesday, March 11, 2009 11:01 AM
Hi TomTom1234,

You're welcome. Now I can undertand your feeling and your curiosity. It's a pity that I haven't given you the exact reason since I am lack of the resource to make a repro. But I am glad to see you can work around this problem.

The problem needs debuging much more which itself needs great patience. Try to comment some part of your program at a time, and run the application. This will help you narrow down the problem.

If you need any help in the process of debuging or going through difficult problems, feel free to let me know.


Best regards,
Bruce Zhou

Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Wednesday, March 11, 2009 1:34 PM

You can use google to search for other answers

Custom Search

More Threads

• Track the Shift Tab key in Textbox
• Password in PropertyGrid
• How to Dock a control in a custom ContainerControl without hiding its custom draw caption at the top?
• Resize the combobox arrow
• designer on derived controls
• List type property, designer update problem
• Error in VB project
• Need a solution for properties that accept array or any workaround?
• determine app path from within a UITypeEditor
• a model of label