set custom date format for bound textbox?

R

Rich

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
 
C

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top