Link to home
Start Free TrialLog in
Avatar of PACCAST-DEV
PACCAST-DEVFlag for United States of America

asked on

Validation problems when users blank out a textbox bound to a number field in vb.net windows app.

In my VS 2008 vb.net project I have some textboxes bound to number fields in the DB. when the user enters a number, then blanks out the number and moves off the textbox and tries to save the record it fails because it trys to save an empty string in the record.
How can I best handle this?

thanks,
bmutch
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike McCracken
Mike McCracken

That is one method if you want NULLs in the field.

Generally I handle this through the LostFocus event.  I check if the value is valid and if not don't let them leave the textbox until they put a valid value in it.

mlmcc
Avatar of PACCAST-DEV

ASKER

Yes, I do allow nulls in these number fields.
Dhaest: - I have to declare this binding variable for every (about 10) field I want to take care of in this manner?
where does this line go:
aBinding .Parse +=new ConvertEventHandler(Parse_Handler);
 and this line gives error:
If e.Value.[GetType]() = Type.[GetType]("System.String") Then
error : operator = is not defined for types system.type...
looks like I got it working, lot of hassle to just take care of the empty textbox...
I used a variation of the "Binding" method above. Am dissappointed that this is so hard to do in VS...