473,320 Members | 2,189 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,320 software developers and data experts.

Datetime format in textbox

I know someone post the solution before, but I didn't keep in mind .
So I am sorry to ask the same question again
I had bind a datatime to the textbox name txtInvoice

I want it displayed in dd-mm-yyyy
I try txtInvoice.txt = Format(txtInvoice.txt,"dd-mm-yyyy"), its return
error.
Anyone know to do it ??
Thanks
Nov 20 '05 #1
13 9350
* "Agnes" <ag***@dynamictech.com.hk> scripsit:
I had bind a datatime to the textbox name txtInvoice

I want it displayed in dd-mm-yyyy
I try txtInvoice.txt = Format(txtInvoice.txt,"dd-mm-yyyy"), its return
error.


\\\
Dim d As Date = Date.Parse(txtInvoice.Text)
txtInvoice.Text = d.ToString(...)
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Hi Agnes,

It was still on my clipboard as answer to John,

I hope this helps?

Cor

Private Sub myroutine()
Mybinding = New Binding("Text", ds.Tables(0), "mydatfield")
textdatfield.DataBindings.Add(Mybinding)
AddHandler mybinding.Format, AddressOf DBdateTextbox
AddHandler mybinding.Parse, AddressOf TextBoxDBdate
End sub
Private Sub DBdateTextbox(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value Is DBNull.Value Then
cevent.Value = ""
Else
Dim datum As Date
datum = CDate(cevent.Value)
cevent.Value = datum.ToString("dd - MM - yyyy")
End If
End Sub
Private Sub TextBoxDBdate(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value.ToString = "" Then
cevent.Value = DBNull.Value
End If
End Sub
///
Nov 20 '05 #3
Dear Cor,
It works BUT as i want to overwrite the date , it won't allow . I over
the date e.g 15-07-2004 to 05-07-2004,after press'tab'
It changed back into '15-07-2004'
Please ~~~
From AGnes
p.s- Your got a cliboard ?? where is it ?

"Cor Ligthert" <no**********@planet.nl> ¦b¶l¥ó
news:OC**************@TK2MSFTNGP12.phx.gbl ¤¤¼¶¼g...
Hi Agnes,

It was still on my clipboard as answer to John,

I hope this helps?

Cor

Private Sub myroutine()
Mybinding = New Binding("Text", ds.Tables(0), "mydatfield")
textdatfield.DataBindings.Add(Mybinding)
AddHandler mybinding.Format, AddressOf DBdateTextbox
AddHandler mybinding.Parse, AddressOf TextBoxDBdate
End sub
Private Sub DBdateTextbox(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value Is DBNull.Value Then
cevent.Value = ""
Else
Dim datum As Date
datum = CDate(cevent.Value)
cevent.Value = datum.ToString("dd - MM - yyyy")
End If
End Sub
Private Sub TextBoxDBdate(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value.ToString = "" Then
cevent.Value = DBNull.Value
End If
End Sub
///

Nov 20 '05 #4
Hi Agnes,

What is the standard time notation in Hongkong?

Cor

ps my clipboard was the place I had copied things.
It works BUT as i want to overwrite the date , it won't allow . I over
the date e.g 15-07-2004 to 05-07-2004,after press'tab'
It changed back into '15-07-2004'
Please ~~~
From AGnes
p.s- Your got a cliboard ?? where is it ?

"Cor Ligthert" <no**********@planet.nl> ¦b¶l¥ó
news:OC**************@TK2MSFTNGP12.phx.gbl ¤¤¼¶¼g...
Hi Agnes,

It was still on my clipboard as answer to John,

I hope this helps?

Cor

Private Sub myroutine()
Mybinding = New Binding("Text", ds.Tables(0), "mydatfield")
textdatfield.DataBindings.Add(Mybinding)
AddHandler mybinding.Format, AddressOf DBdateTextbox
AddHandler mybinding.Parse, AddressOf TextBoxDBdate
End sub
Private Sub DBdateTextbox(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value Is DBNull.Value Then
cevent.Value = ""
Else
Dim datum As Date
datum = CDate(cevent.Value)
cevent.Value = datum.ToString("dd - MM - yyyy")
End If
End Sub
Private Sub TextBoxDBdate(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value.ToString = "" Then
cevent.Value = DBNull.Value
End If
End Sub
///


Nov 20 '05 #5
Standard time notation in Hong kong ? normally dd-mm-yyyy
If i used in vfp . it is called italian date format

From Agnes

"Cor Ligthert" <no**********@planet.nl> ¦b¶l¥ó
news:OG**************@TK2MSFTNGP10.phx.gbl ¤¤¼¶¼g...
Hi Agnes,

What is the standard time notation in Hongkong?

Cor

ps my clipboard was the place I had copied things.
It works BUT as i want to overwrite the date , it won't allow . I over the date e.g 15-07-2004 to 05-07-2004,after press'tab'
It changed back into '15-07-2004'
Please ~~~
From AGnes
p.s- Your got a cliboard ?? where is it ?

"Cor Ligthert" <no**********@planet.nl> ¦b¶l¥ó
news:OC**************@TK2MSFTNGP12.phx.gbl ¤¤¼¶¼g...
Hi Agnes,

It was still on my clipboard as answer to John,

I hope this helps?

Cor

Private Sub myroutine()
Mybinding = New Binding("Text", ds.Tables(0), "mydatfield")
textdatfield.DataBindings.Add(Mybinding)
AddHandler mybinding.Format, AddressOf DBdateTextbox
AddHandler mybinding.Parse, AddressOf TextBoxDBdate
End sub
Private Sub DBdateTextbox(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value Is DBNull.Value Then
cevent.Value = ""
Else
Dim datum As Date
datum = CDate(cevent.Value)
cevent.Value = datum.ToString("dd - MM - yyyy")
End If
End Sub
Private Sub TextBoxDBdate(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value.ToString = "" Then
cevent.Value = DBNull.Value
End If
End Sub
///



Nov 20 '05 #6
Hi Agnes,

Before I wrote this message I tested it completly again, while I have used
it before, however I could not simulate your problem so show some code as
you have implemented it?

Cor
Nov 20 '05 #7
I just wrote a simple form with 2 textbox , txtDate is binded as following
As form load, it showed my data e.g 19-05-2004, and then i overwrite the
date field into '20-05-2004' ,press tab
it changed back into '19-05-2004'
Anything I done wrong ???
From Agnes

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
daTest.Fill(DsTest)
Dim Mybinding As New Binding("Text", DsTest.Tables(0), "date")
txtDate.DataBindings.Add(Mybinding)
AddHandler txtDate.DataBindings("Text").Format, AddressOf
DBdateTextbox
AddHandler txtDate.DataBindings("Text").Parse, AddressOf
TextBoxDBdate
End Sub

"Cor Ligthert" <no**********@planet.nl> ¦b¶l¥ó
news:e3**************@tk2msftngp13.phx.gbl ¤¤¼¶¼g...
Hi Agnes,

Before I wrote this message I tested it completly again, while I have used
it before, however I could not simulate your problem so show some code as
you have implemented it?

Cor

Nov 20 '05 #8
Hi Agnes,

Can you try this sample, it needs one textbox and one button on a form.

I hope this helps?

Cor

\\\
Dim dt As New DataTable
Private Sub Form4_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add(New DataColumn("mydate", GetType(System.DateTime)))
dt.Rows.Add(dt.NewRow)
Dim Mybinding As New Binding("Text", dt, "mydate")
TextBox1.DataBindings.Add(Mybinding)
AddHandler Mybinding.Format, AddressOf DBdateTextbox
AddHandler Mybinding.Parse, AddressOf TextBoxDBdate
dt.Rows(0)("mydate") = New Date(2004, 7, 15)
End Sub
Private Sub DBdateTextbox(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value Is DBNull.Value Then
cevent.Value = ""
Else
Dim datum As Date
datum = CDate(cevent.Value)
cevent.Value = datum.ToString("dd - MM - yyyy")
End If
End Sub
Private Sub TextBoxDBdate(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value.ToString = "" Then
cevent.Value = DBNull.Value
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
BindingContext(dt).EndCurrentEdit()
MessageBox.Show(dt.Rows(0)(0).ToString)
End Sub
///
Nov 20 '05 #9
Dear Cor,
I just try it.. [I overwrite the date to 16-07-2004 ,after press button
, it changed back >_< ]
Anyway, thanks for your kind help and coding.
I will try my best to search thr internet and seek the solution.
Thanks in advance
From Agnes

"Cor Ligthert" <no**********@planet.nl> ¦b¶l¥ó
news:%2****************@tk2msftngp13.phx.gbl ¤¤¼¶¼g...
Hi Agnes,

Can you try this sample, it needs one textbox and one button on a form.

I hope this helps?

Cor

\\\
Dim dt As New DataTable
Private Sub Form4_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add(New DataColumn("mydate", GetType(System.DateTime)))
dt.Rows.Add(dt.NewRow)
Dim Mybinding As New Binding("Text", dt, "mydate")
TextBox1.DataBindings.Add(Mybinding)
AddHandler Mybinding.Format, AddressOf DBdateTextbox
AddHandler Mybinding.Parse, AddressOf TextBoxDBdate
dt.Rows(0)("mydate") = New Date(2004, 7, 15)
End Sub
Private Sub DBdateTextbox(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value Is DBNull.Value Then
cevent.Value = ""
Else
Dim datum As Date
datum = CDate(cevent.Value)
cevent.Value = datum.ToString("dd - MM - yyyy")
End If
End Sub
Private Sub TextBoxDBdate(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value.ToString = "" Then
cevent.Value = DBNull.Value
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
BindingContext(dt).EndCurrentEdit()
MessageBox.Show(dt.Rows(0)(0).ToString)
End Sub
///

Nov 20 '05 #10
Dear Great Cor,
I add this statment before Bindingcontext.endcurrentedit()
[dt.Rows(0)("mydate") = TextBox1.Text]
It seems work and accept my overwrite, I will try it more and let u know the
result

From Agnes

"Agnes" <ag***@dynamictech.com.hk> ¦b¶l¥ó
news:ee**************@TK2MSFTNGP11.phx.gbl ¤¤¼¶¼g...
Dear Cor,
I just try it.. [I overwrite the date to 16-07-2004 ,after press button , it changed back >_< ]
Anyway, thanks for your kind help and coding.
I will try my best to search thr internet and seek the solution.
Thanks in advance
From Agnes

"Cor Ligthert" <no**********@planet.nl> ¦b¶l¥ó
news:%2****************@tk2msftngp13.phx.gbl ¤¤¼¶¼g...
Hi Agnes,

Can you try this sample, it needs one textbox and one button on a form.

I hope this helps?

Cor

\\\
Dim dt As New DataTable
Private Sub Form4_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add(New DataColumn("mydate", GetType(System.DateTime))) dt.Rows.Add(dt.NewRow)
Dim Mybinding As New Binding("Text", dt, "mydate")
TextBox1.DataBindings.Add(Mybinding)
AddHandler Mybinding.Format, AddressOf DBdateTextbox
AddHandler Mybinding.Parse, AddressOf TextBoxDBdate
dt.Rows(0)("mydate") = New Date(2004, 7, 15)
End Sub
Private Sub DBdateTextbox(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value Is DBNull.Value Then
cevent.Value = ""
Else
Dim datum As Date
datum = CDate(cevent.Value)
cevent.Value = datum.ToString("dd - MM - yyyy")
End If
End Sub
Private Sub TextBoxDBdate(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value.ToString = "" Then
cevent.Value = DBNull.Value
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
BindingContext(dt).EndCurrentEdit()
MessageBox.Show(dt.Rows(0)(0).ToString)
End Sub
///


Nov 20 '05 #11
Oh my god, from 15-07-2004 to 16-07-2004 is ok .
however, 15-08-2004 , it got invalid datetime error

"Agnes" <ag***@dynamictech.com.hk> ¦b¶l¥ó
news:ee**************@TK2MSFTNGP11.phx.gbl ¤¤¼¶¼g...
Dear Cor,
I just try it.. [I overwrite the date to 16-07-2004 ,after press button , it changed back >_< ]
Anyway, thanks for your kind help and coding.
I will try my best to search thr internet and seek the solution.
Thanks in advance
From Agnes

"Cor Ligthert" <no**********@planet.nl> ¦b¶l¥ó
news:%2****************@tk2msftngp13.phx.gbl ¤¤¼¶¼g...
Hi Agnes,

Can you try this sample, it needs one textbox and one button on a form.

I hope this helps?

Cor

\\\
Dim dt As New DataTable
Private Sub Form4_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add(New DataColumn("mydate", GetType(System.DateTime))) dt.Rows.Add(dt.NewRow)
Dim Mybinding As New Binding("Text", dt, "mydate")
TextBox1.DataBindings.Add(Mybinding)
AddHandler Mybinding.Format, AddressOf DBdateTextbox
AddHandler Mybinding.Parse, AddressOf TextBoxDBdate
dt.Rows(0)("mydate") = New Date(2004, 7, 15)
End Sub
Private Sub DBdateTextbox(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value Is DBNull.Value Then
cevent.Value = ""
Else
Dim datum As Date
datum = CDate(cevent.Value)
cevent.Value = datum.ToString("dd - MM - yyyy")
End If
End Sub
Private Sub TextBoxDBdate(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value.ToString = "" Then
cevent.Value = DBNull.Value
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
BindingContext(dt).EndCurrentEdit()
MessageBox.Show(dt.Rows(0)(0).ToString)
End Sub
///


Nov 20 '05 #12
Hi Agnes,

You can be sure that I tested this, this is a one piece complete testable
new build solution.

So in this sample it should do it. Or do you not mean that with this
message?

Cor
Dear Cor,
I just try it.. [I overwrite the date to 16-07-2004 ,after press button , it changed back >_< ]
Anyway, thanks for your kind help and coding.
I will try my best to search thr internet and seek the solution.
Thanks in advance
From Agnes

Nov 20 '05 #13
That is because you need to create a custom databinding object with an
event that handles the formating and add the format function in there.
Ex.

Dim WithEvents oBinding As Binding
dim oDt as new Dataset'Make sure this is the correct dataset you are
binding the text box to.

private sub BindData()
'A new binding object declared above using "WithEvents" is explicitly
created that
'binds the text field to the "GetDateTime" property of the
MyDateTime class.
'The binding object is then added to the textbox's databindings
collection.

oBinding = New Binding("Text", oDt, "GetDateTime")
txt1.DataBindings.Add(oBinding)
txt2.DataBindings.Add("Text", oDt, "GetDateTime")
end sub

Private Sub oBinding_Format(ByVal sender As Object, ByVal e
As System.Windows.Forms.ConvertEventArgs) Handles
oBinding.Format
e.Value = Format(e.Value, "MM/dd/yy")
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
BindData()
end sub

Brad Shook
Programmer/Analysts II
Nov 20 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Carl | last post by:
Hi, to be use with SQL server database 1- From window form textbox object From this assignement, txtTOTAL.Text="0.00m"; How do you convert back to decimal type ? How do you assign a...
3
by: Iwan Petrow | last post by:
Hi, I have a column of type datetime in a SQL Server database. I set and get this column with Web Services using dataset and send them to a Web App TextBox control. The collation of the database...
1
by: Lerp | last post by:
Hi all, What do I have to do in order to get my value from my textbox that is formatted like 'mm/dd/yyyy' into a datetime database field ? Currently getting an error: Syntax error converting...
1
by: adolf garlic | last post by:
I'm having a problem with dates. (No not the sort that you have at christmas) I have a webform with a text box and a calendar control. You can either - enter a date manually (we are talking uk...
2
by: Boonaap | last post by:
Hi all, In a user control, the user can put the cultureinfo to his preference, choosing between "nl-BE","fr-BE", and "en-US". this way all calendar and datetime properties are set in the right...
9
by: Simon Harvey | last post by:
Hi all, I'm having a bit of a problem working with dates. My computer is british, but I'm developing an american application so I therefore need to use american dates. But I can't get my...
11
by: Axel Dahmen | last post by:
Hi, I'm working in a team developing an international website. When I set the page's CultureInfo to Hungarian (hu-HU) then the RangeValidator doesn't seem to be able to parse a TextBox's date...
5
by: js | last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss". I need to parse the text using System.DateTime.Parse() function with custom format. I got an error using the following code. ...
3
by: David | last post by:
I am using .Net 2.0 and VS2005 with SQL server db. The datetime columns on SQL have the date and time in them. How can I display just the short date format (e.g. a datetime of 10/19/2006 11:23:57...
9
by: Hrvoje Voda | last post by:
How to convert text from textbox "12.05.1977" into "12/05/1977"? and also check if the text is in right format before converting? Hrcko
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.