PC Review


Reply
Thread Tools Rate Thread

Datetime format in textbox

 
 
Agnes
Guest
Posts: n/a
 
      10th Jul 2004
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


 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      10th Jul 2004
* "Agnes" <(E-Mail Removed)> 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/>
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      11th Jul 2004
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
///


 
Reply With Quote
 
Agnes
Guest
Posts: n/a
 
      12th Jul 2004
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" <(E-Mail Removed)> 秎ン
news:(E-Mail Removed) い级糶...
> 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
> ///
>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      12th Jul 2004
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" <(E-Mail Removed)> 秎ン
> news:(E-Mail Removed) い级糶...
> > 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
> > ///
> >
> >

>
>



 
Reply With Quote
 
Agnes
Guest
Posts: n/a
 
      13th Jul 2004
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" <(E-Mail Removed)> 秎ン
news:(E-Mail Removed) い级糶...
> 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" <(E-Mail Removed)> 秎ン
> > news:(E-Mail Removed) い级糶...
> > > 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
> > > ///
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Jul 2004
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


 
Reply With Quote
 
Agnes
Guest
Posts: n/a
 
      13th Jul 2004
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" <(E-Mail Removed)> 秎ン
news:(E-Mail Removed) い级糶...
> 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
>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Jul 2004
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
///


 
Reply With Quote
 
Agnes
Guest
Posts: n/a
 
      13th Jul 2004
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" <(E-Mail Removed)> 秎ン
news:%(E-Mail Removed) い级糶...
> 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
> ///
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert a latebinded DataTable column's format from DateTime to string (or format the date time value) RSH Microsoft VB .NET 0 6th Dec 2006 03:49 PM
Revert VS 2005 DataSet.GetXML() DateTime Format back to VS 2003 Format? samtilden@gmail.com Microsoft C# .NET 0 8th Jun 2006 11:25 PM
DateTime Bound to TextBox =?Utf-8?B?bWFyaw==?= Microsoft Dot NET Framework Forms 2 2nd Dec 2004 06:25 PM
DateTime problem: how to create datetime format hh:mm:ss AM/PM without the date mimi Microsoft C# .NET 1 6th Aug 2004 08:28 PM
newbie questions on TextBox and DateTime Danny Ni Microsoft ASP .NET 3 13th Apr 2004 01:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:56 AM.