Solved

C# MaskedTextBox -- ignore BLANK text ?

Posted on 2012-03-14
5
510 Views
Last Modified: 2012-03-24
How can I change the below so when users remove a date from the below TEXTBOX and click "TAB" it goes to the next control ?

Currently FOCUS remains on the current control and their only option is to enter a bogus date like 09/09/2099.

        private void dATE_DISTRUBUTEDMaskedTextBox_Validating(object sender, CancelEventArgs e)
        {
            if (dATE_DISTRUBUTEDMaskedTextBox.Text == "  /  /")
            {
                e.Cancel = true;
            }
        }
0
Comment
Question by:finance_teacher
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 37719889
try <nextcontrol>.Focus();
<nextcontrol> being the name of the next control eg: textbox2
0
 

Author Comment

by:finance_teacher
ID: 37720053
That also fails, keeping focus in the original control.
0
 
LVL 9

Expert Comment

by:gery128
ID: 37720165
According to following link, you can use this property of MaskedTextBox to go ahead with blank space:

dATE_DISTRUBUTEDMaskedTextBox.ResetOnSpace = false;

http://stackoverflow.com/questions/8334838/can-a-winforms-maskedtextbox-allow-spaces
0
 
LVL 9

Accepted Solution

by:
gery128 earned 500 total points
ID: 37720216
Can you try this? this will allow blank/empty date input (e.g. textbox with no date but mask only)
  private void dATE_DISTRUBUTEDMaskedTextBox_Validating(object sender, CancelEventArgs e)
        {
            if (dATE_DISTRUBUTEDMaskedTextBox.Text == "  /  /")
            {
                e.Cancel = false;
            }
        }

Open in new window

0
 

Author Comment

by:finance_teacher
ID: 37721134
Both of the above failed, e.Cancel ran, but kept focus on the current control.
0

Featured Post

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

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

706 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

17 Experts available now in Live!

Get 1:1 Help Now