Data binding a date to a text box

P

Paul Hester

I have a data binding issue that I was hoping someone could help me
with.

We have converted a VB6 app to .NET unsung a conversion tool that came
with .NET studio. Instead of converting the ADO code to ADO.NET it
used COM interop to call to continue to use ADO objects.

In the app sever date fields are bound to date data fields. In the old
app after data binding the date would show with just the date
(1/1/2000). After the app was converted the text boxes now show the
date and time (1/1/2000 12:00 AM). When I edit the text box by
deleting the time and TAB out of the field the binding immediatly adds
it back in.

I know that if we were to manually convert the app to use ADO.NET I
could attach to events on the Binding object that is put into the
TextBox.DataBindings collection
(http://www.kdkeys.net/forums/715/ShowPost.aspx). However due to
budget constraints this is not feasible.

I have checked all the properties and events on the textbox and ADO
bindings to try to get the time out of the text box with no success.

Is there any way I can get the time out of the text box using ADO
through COM interop?
 
G

Guest

Here is what I did for a similar issue. I formatted the value as
ToShortDateString

'In the binding routine
b = New Binding("Text", dr, "EffectiveDate")
AddHandler b.Parse, AddressOf DataBindingManager.CurrencyStringtoDate
AddHandler b.Format, AddressOf DataBindingManager.DateToCurrencyString
Me.txtEffectiveDate.DataBindings.Add(b)

'Handler for binding format
Public Shared Sub DateToCurrencyString(ByVal sender As Object, ByVal e As
System.windows.forms.ConvertEventArgs)

If e.Value Is System.DBNull.Value Then
e.Value = ""
Else
e.Value = CType(e.Value, Date).ToShortDateString.ToString
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