Solved

MaskedTextBox - TextChanged Event Throws Error

Posted on 2012-03-28
6
857 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

896 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now