Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Masked Text Box and Date Format

Status
Not open for further replies.

Bluejay07

Programmer
Mar 9, 2007
780
CA
I have a masked text box which is displaying a date from a dataset.

The mask is 00/00/0000 and a prompt character of -, thus displaying as --/--/---- to the user.

My problem is how the date is displayed. For example, if I have a date 1/25/2008, it is being displayed as 12/52/008-.

I have also tried
- mask: 99/99/9999
- FormatDateTime with DateFormat.ShortDate
- changing the TextMaskFormat to MaskFormat.ExcludePromptAndLiterals

and still received the same result.

Can anyone help?
 
How are you populating the text box?
Are you dynamically linked to it, though something like a data adapter?
Did you manually hook up the row in the dataset to the masked text box?

If you are doing the retrieval from the dataset manually then you just have to "build" your date before you put it in the box, because the masked text box is expecting a zero where then isn't one.

I was going to suggest just setting your textbox as a rightToLeft, but you would still have problems with datas that use the first 9 days of the month.

-Sometimes the answer to your question is the hack that works
 
Qik3Coder,

I am using da.SelectCommand for the command and connection with the use of a stored procedure from SQL Server 2005 to obtain the values from the database.

I then use da.fill(ds, "Name") to populate the dataset.

The date is a value stored in the table which I am referencing and displaying on the form.
 
ok, you are doing it through a datasource, that you don't have a whole lot of control over between the database and the display.

You can either pad the display from the stored procedure, so that you get 01/01/2001

or

You can change the Maskedtextbox to a textbox with a Regex function on it to validate the data as a date. You could also validate the data some other way, but the regex is usally fastest, you would verify your data as a date in the Leave or LostFocus event or something similar.

-Sometimes the answer to your question is the hack that works
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top