I have a textbox which is bound to a dataset and a leave event which changes the textbox.text value. The problem is it is changing in the debugger but goes back to original value on the form???!! Any ideas?
What I'm trying to do is have the textbox display a SQL money field with currency formatting. This has lead to an interesting trip through VB.net binding and event handling. The following is for your info and comment:
When textboxes have databindings, the CausesValidating property is set to true automatically. When this occurs some validating occurs against bound data field type. Thus when you try to enter letters in a textbox bound to a money field, it gives you little red exclamation and rejects input. You can override the CausesValidating in the IDE (set it to false).
Since I wanted to format the textbox on load, etc. I needed to do the formatting in the TextChanged event. Unfortunately, this created problems when in the field and changing the text as this event is also fired on every keystroke. What I wound up doing is to remove the event handler for TextChanged event of textbox when in the Enter event. I restore this event when the Leave and LostFocus events are fired. As ugly as this is, it does seem to work! The only problem is I will get a System.Format.Exception error on bindings when I try to update record but only IF I TRAP FOR IT IN DEBUGGER!!! If I don't ... the data goes through okay??
I'm sure there might be other ways to do this. Perhaps working with a Validating event. A more interesting possibility is to create a custom textbox control with a "shadow" text field used for display. What do you guys think?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.