By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,744 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

formatting a texbox to show date in specific format...

P: n/a
Hi
I have a dataform that shows a date from a MSDE 2000 in a textbox.
It uses the format: dd-mm-yyyy hh:mm:ss
It would it to use the format dd-mm-yyyy
But I can't find a Format property for the textbox.
So I tried in the VB code the wizard generates

Me.editDateOfBirth.DataBindings.Add(New System.Windows.Forms.Binding("Text",
Me.objDSBoerneKirken, "tPersoner.DateOfBirth"))
Me.editDateOfBirth.Location = New System.Drawing.Point(120, 604)
Me.editDateOfBirth.Name = "editDateOfBirth"
Me.editDateOfBirth.TabIndex = 37
Me.editDateOfBirth.Text = ""
' Me.editDateOfBirth.Text.Format("short date") My addition that does not
work

Any suggestions?

Best regards
Jan Nielsen

Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
* "Jan Nielsen" <Re**************@tiscali.dk> scripsit:
I have a dataform that shows a date from a MSDE 2000 in a textbox.
It uses the format: dd-mm-yyyy hh:mm:ss
It would it to use the format dd-mm-yyyy
But I can't find a Format property for the textbox.
So I tried in the VB code the wizard generates


Why not use a DateTimePicker control?

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

P: n/a
Hi,

If you have a databound textbox you can use the format event. Add a
handler after you bind the textbox. The textbox format event will fire the
next time the control redraws or the data changes.

txtDate.DataBindings.Add("Text", dvInvoice, "BillDate")

AddHandler txtDate.DataBindings(0).Format, AddressOf Me.FormatDate

===========The procedure===========

Private Sub FormatDate(ByVal sender As Object, ByVal e As ConvertEventArgs)

Dim dt As Date

Try

dt = e.Value

e.Value = dt.ToShortDateString 'Format(e.Value, "MMM d, yyyy")

Catch

e.Value = "Unknown"

End Try

End Sub

Ken

----------------------------

"Jan Nielsen" <Re**************@tiscali.dk> wrote in message
news:ea**************@tk2msftngp13.phx.gbl...
Hi
I have a dataform that shows a date from a MSDE 2000 in a textbox.
It uses the format: dd-mm-yyyy hh:mm:ss
It would it to use the format dd-mm-yyyy
But I can't find a Format property for the textbox.
So I tried in the VB code the wizard generates

Me.editDateOfBirth.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.objDSBoerneKirken, "tPersoner.DateOfBirth"))
Me.editDateOfBirth.Location = New System.Drawing.Point(120, 604)
Me.editDateOfBirth.Name = "editDateOfBirth"
Me.editDateOfBirth.TabIndex = 37
Me.editDateOfBirth.Text = ""
' Me.editDateOfBirth.Text.Format("short date") My addition that does not
work

Any suggestions?

Best regards
Jan Nielsen

Nov 20 '05 #3

P: n/a
Because I did not know the existence of such a control ;-)
Thanks for informing me.
And I can even make my own custom format!
Best regards

Jan

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> skrev i en meddelelse
news:uC****************@tk2msftngp13.phx.gbl...
* "Jan Nielsen" <Re**************@tiscali.dk> scripsit:
I have a dataform that shows a date from a MSDE 2000 in a textbox.
It uses the format: dd-mm-yyyy hh:mm:ss
It would it to use the format dd-mm-yyyy
But I can't find a Format property for the textbox.
So I tried in the VB code the wizard generates


Why not use a DateTimePicker control?

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #4

P: n/a
Hi Ken
Herfrieds solution is simpler but you answered my question exactly and
taught me something about how to program VB.Net properly. Which I value a
lot since I am trying to learn VB.Net.
Thanks a lot!

Best regards

Jan
"Ken Tucker [MVP]" <vb***@bellsouth.net> skrev i en meddelelse
news:e1**************@TK2MSFTNGP10.phx.gbl...
Hi,

If you have a databound textbox you can use the format event. Add a handler after you bind the textbox. The textbox format event will fire the next time the control redraws or the data changes.

txtDate.DataBindings.Add("Text", dvInvoice, "BillDate")

AddHandler txtDate.DataBindings(0).Format, AddressOf Me.FormatDate

===========The procedure===========

Private Sub FormatDate(ByVal sender As Object, ByVal e As ConvertEventArgs)
Dim dt As Date

Try

dt = e.Value

e.Value = dt.ToShortDateString 'Format(e.Value, "MMM d, yyyy")

Catch

e.Value = "Unknown"

End Try

End Sub

Ken

----------------------------

"Jan Nielsen" <Re**************@tiscali.dk> wrote in message
news:ea**************@tk2msftngp13.phx.gbl...
Hi
I have a dataform that shows a date from a MSDE 2000 in a textbox.
It uses the format: dd-mm-yyyy hh:mm:ss
It would it to use the format dd-mm-yyyy
But I can't find a Format property for the textbox.
So I tried in the VB code the wizard generates

Me.editDateOfBirth.DataBindings.Add(New

System.Windows.Forms.Binding("Text",
Me.objDSBoerneKirken, "tPersoner.DateOfBirth"))
Me.editDateOfBirth.Location = New System.Drawing.Point(120, 604)
Me.editDateOfBirth.Name = "editDateOfBirth"
Me.editDateOfBirth.TabIndex = 37
Me.editDateOfBirth.Text = ""
' Me.editDateOfBirth.Text.Format("short date") My addition that does not
work

Any suggestions?

Best regards
Jan Nielsen


Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.