468,469 Members | 2,249 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,469 developers. It's quick & easy.

set custom date format for bound textbox?

Hello,

I have some datefields in a dataset (ds1). I bind some
textbox controls on a windows form to these date fields in
ds1, but I only want to see 01/01/2004 instead of 1/1/2004
8:00:00 AM. In a DateTimePicker control I can set a
custom format("MM/dd/yyyy"). So when I iterate through
ds1 with currency manager (cma) I see the correct date
format in a DateTimePicker control. Is it possible to set
a custom date format like that for a bound textbox
control? I realize that for every event where I could
increment cma I could say txtDate.Text = Format(ds1....)
but that kind of defeats the idea of a bound textbox. Is
there a way to set a custom format for a textbox like on
the form_load evnet?

Thanks,
Rich
Nov 20 '05 #1
1 9148
Cor
Hi Rich,

I made a sample for you, but did not test it.

Can you try it and tell me if it is complete, than I can use it the next
time as sample and not have to write the sentence above?

(The date is in EU format of course so you have to change that to US)

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
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
///

I have some datefields in a dataset (ds1). I bind some
textbox controls on a windows form to these date fields in
ds1, but I only want to see 01/01/2004 instead of 1/1/2004
8:00:00 AM. In a DateTimePicker control I can set a
custom format("MM/dd/yyyy"). So when I iterate through
ds1 with currency manager (cma) I see the correct date
format in a DateTimePicker control. Is it possible to set
a custom date format like that for a bound textbox
control? I realize that for every event where I could
increment cma I could say txtDate.Text = Format(ds1....)
but that kind of defeats the idea of a bound textbox. Is
there a way to set a custom format for a textbox like on
the form_load evnet?

Thanks,
Rich

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by J. Muenchbourg | last post: by
2 posts views Thread by Derek Vincent | last post: by
2 posts views Thread by paulquinlan100 | last post: by
4 posts views Thread by Allen Browne | last post: by
6 posts views Thread by =?Utf-8?B?QmVu?= | last post: by
3 posts views Thread by EdisonCPP | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.