By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,677 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,677 IT Pros & Developers. It's quick & easy.

set custom date format for bound textbox?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.