Solved

MaskedTextBox - TextChanged Event Throws Error

Posted on 2012-03-28
6
866 Views
Last Modified: 2012-03-28
Using VB.Net 2010 (Pro)

I hav a form which contains several standard text boxes and a few MaskedTextBox controls I use for date input (ie set mask format to short date).

I want to know when the form becomes "dirty", so I've put code to check the values in the text boxes against the original data.  This has worked fine for standard text boxes, which I put code in the "TextChanged" event to test for "dirty".  For that standard textboxes, I've combined the "TextChanged" handler into one single routine.

However, when I try the same thing for a MaskedTextBox, when starting the application it immediately throws an error that reads:
Value cannot be null
All I have done to get this error is add the "TextChanged" event,  I have not yet even put code in the event.

I have tried both having a seperate handler, as well as combining it with the standard TextBox handlers.  Both fail with the same error.

What's going on and, more importantly, how go I get it to work?

TIA
0
Comment
Question by:Clif
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:Rainverse
ID: 37776776
I do not believe the .Net maskedtextbox supports null values. In other words, it has to have a default value to begin with and compare to when the value is changed.

-MJC
0
 
LVL 10

Author Comment

by:Clif
ID: 37776831
That explains the problem but doesn't offer a solution.
0
 
LVL 5

Expert Comment

by:Rainverse
ID: 37776977
Give it a default value. Any date will do. It just won't validate against a Null value.  (i.e. does myDate = Null)

-MJC
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 16

Accepted Solution

by:
Rose Babu earned 500 total points
ID: 37776978
instead of "TextChanged" event can you use "Leave" event of a "MaskedTextBox "? then test the application once.
0
 
LVL 10

Author Comment

by:Clif
ID: 37777129
Rainverse,

I can't put a default date, if there is no date to put (ie, it's not a financed vehicle, so there is no Payoff date).  Putting an arbitrary date in would be confusng to the user.

This is the reason I went with the MaskedTextBox instead of the DateTimePicker.
0
 
LVL 10

Author Closing Comment

by:Clif
ID: 37777149
The Leave event seems to work as I need.

Thanks.  :)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question