Solved

MaskedTextBox - TextChanged Event Throws Error

Posted on 2012-03-28
6
843 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
Comment Utility
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
Comment Utility
That explains the problem but doesn't offer a solution.
0
 
LVL 5

Expert Comment

by:Rainverse
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 16

Accepted Solution

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

Author Comment

by:Clif
Comment Utility
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
Comment Utility
The Leave event seems to work as I need.

Thanks.  :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

7 Experts available now in Live!

Get 1:1 Help Now