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

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

Post by Jan Nielse » Sun, 12 Oct 2003 18:26:58


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
 
 
 

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

Post by hirf-spam- » Sun, 12 Oct 2003 20:25:02

* "Jan Nielsen" < XXXX@XXXXX.COM > scripsit:

Why not use a DateTimePicker control?

--
Herfried K. Wagner
MVP VB Classic, VB.NET << http://www.yqcomputer.com/ ;>

 
 
 

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

Post by Ken Tucker » Mon, 13 Oct 2003 01:33:13

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

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



System.Windows.Forms.Binding("Text",
 
 
 

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

Post by Jan Nielse » Tue, 14 Oct 2003 19:24:25

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]" < XXXX@XXXXX.COM > skrev i en meddelelse
 
 
 

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

Post by Jan Nielse » Tue, 14 Oct 2003 19:27:22

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]" < XXXX@XXXXX.COM > skrev i en meddelelse

a
the
ConvertEventArgs)