Solved

MaskedTextBox - TextChanged Event Throws Error

Posted on 2012-03-28
6
883 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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