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

  • Thread starter Thread starter Jan Nielsen
  • Start date Start date
J

Jan Nielsen

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
 
* "Jan Nielsen said:
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?
 
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
 
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
 
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
 
Back
Top