Solved

C# MaskedTextBox -- ignore BLANK text ?

Posted on 2012-03-14
5
523 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
[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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

Suggested Solutions

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.
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ā€¦

734 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