Format data in bound textbox as date

G

Graeme Richardson

Hi, I want to format a bound text box to display a date in "dd-mmm-yyyy"
format.
I've written the following code (that doesn't do the job). Any pointers
would be appreciated.

Dim bndBinding As New Binding("Text", "tblContact", "DateOfBirth")
bndBinding.BindingMemberInfo.BindingField.Format("dd-mmm-yyyy")
txtDateOfBirth.DataBindings.Add(bndBinding)

Thanks, Graeme.
 
G

Graeme Richardson

Thanks Miha, I eventually found the event (and the example).
For those that are following the thread, this is the code (summarised from
working code):

Public Sub bindDateOfBirth()

Dim bndBinding As New Binding("Text", "tblContact", "DateOfBirth")
bndBinding.BindingMemberInfo.BindingField.Format("dd-mmm-yyyy")
AddHandler bndBinding.Format, AddressOf DateToString
AddHandler bndBinding.Parse, AddressOf StringToDate

txtDateOfBirth.DataBindings.Add(bndBinding)

End Sub

Private Sub DateToString(ByVal sender As Object, ByVal e As
System.Windows.Forms.ConvertEventArgs)

' Format that data as date
If Not (e.Value Is DBNull.Value) Then
e.Value = CType(e.Value, Date).ToString("d")
End If

End Sub

Private sub StringToDate(ByVal sender As Object, ByVal e As
System.Windows.Forms.ConvertEventArgs)

' Fill in this bit...

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