Solved

MaskedTextBox - TextChanged Event Throws Error

Posted on 2012-03-28
6
873 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
get combo value in class 5 14
MailAddress in vb 4 29
run a stored procedure from vb.net 1 27
How to open a different table using the same bindingsource - vb.net 3 30
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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…

809 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