Solved

C# MaskedTextBox -- ignore BLANK text ?

Posted on 2012-03-14
5
513 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

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

22 Experts available now in Live!

Get 1:1 Help Now