473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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

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
4 5318
* "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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Thomas Philips | last post by:
Consider the following simple dictionary e={1:'one', 2: 'two'} e >>>'one' However, If I attempt to print e using a formatted string print " %(1)s" %e, I get a KeyError: '1'
8
by: the other john | last post by:
I have a client that wants a time field to resolve to 7:00 PM rather than 7:00:00 PM (wants the seconds gone). vbLongTime provides the later but vbShortTime produces a 24 hour version or 19:00. ...
2
by: Sara | last post by:
The problem: Conditional formatting bold, red when field Value < date() sets the field background to white - always - whether condition is met or not. I want the field unfilled and just red/bold...
4
by: deko | last post by:
I've heard it's best not to have any formatting specified for Table fields (except perhaps Currency), and instead set the formatting in the Form or Report. But what about Yes/No fields? When I...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
4
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I...
2
by: johndcal | last post by:
Hello All, I have a date value that I pull from a .csv file. After reading the file and storing the values in an array the value of the date could be found in $array, for example....
2
by: David Hearn | last post by:
I have a formview control in my project (VS2005/ASP.NET 2.0) and I have one field that is a date. I have it formatting correctly as a short date (MM/dd/yyyy) but when I click the edit link to edit...
4
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.