Clif
asked on
MaskedTextBox - Date Doesn't Fit Format
Using VB.Net 2010 (Pro) (the database is SQL Server 2008, if it matters)
In my app, I retrieve data from the database and load textboxes. One of the textboxes is a maskedtextbox. When the date returned from the database is, like, 5/8/2005, the maskedtextbox will display "58/20/05__"
As a side note, this date, (5/8/2005) was put in to the database from this very same control, but it was typed in as 05/08/2005.
How do I get the proper date to display?
TIA
In my app, I retrieve data from the database and load textboxes. One of the textboxes is a maskedtextbox. When the date returned from the database is, like, 5/8/2005, the maskedtextbox will display "58/20/05__"
As a side note, this date, (5/8/2005) was put in to the database from this very same control, but it was typed in as 05/08/2005.
How do I get the proper date to display?
TIA
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
If IsDate(VehicleList(i).Reg_Expr) Then
txtRegExpiry.Text = VehicleList(i).Reg_Expr.ToString("MM/dd/YYYY")
Else
txtRegExpiry.Text = ""
End If
(Yes, it bothers me too that a variable for "Registration Expiration" is named "Reg_Expr", but that's the hand I was dealt.)
Assuming that txtRegExpiry is the MaskedTextBox, set its AllowPromptAsInput property to true before setting the text property.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The combination between explicitly casting to date and formatting to a date string worked.
One small point, though, "MM/dd/YYYY" is invalid. It should have been "MM/dd/yyyy" (lowercase 'y'). With uppercase, the year does not show up.
One small point, though, "MM/dd/YYYY" is invalid. It should have been "MM/dd/yyyy" (lowercase 'y'). With uppercase, the year does not show up.
ASKER
BTW, CodeCruiser, your suggestion did not help. The maskedtextbox's "AllowPromptAsInput" was already set to true (as default, I would guess, since I never set it in the first place).
The uppercase Y slipped past me on my first post... Glad you got it sorted.
ASKER
The variable is a date type and contains the value
#11/15/2011#