Databinding and date formats

Posts   
 
    
Posts: 11
Joined: 02-Aug-2005
# Posted on: 04-Oct-2005 18:32:31   

Hi, this is not really an LLBLGen issue but as you're all so helpful I thought I'd give it a go!

I'm binding date fields from entity objects and formatting the output in the text box in short date format.


        BindDateField(Me.txtCheckIn, "Text", reservation.BookingDetail, "CheckIn")
        BindDateField(Me.txtCustTravleDate, "Text", reservation.BookingDetail, "CheckIn")
        BindDateField(Me.txtCheckOut, "Text", reservation.BookingDetail, "CheckOut")


Public Sub BindDateField(ByVal control As Control, ByVal propertyName As String, ByVal dataSource As Object, ByVal dataMember As String)

        For index = control.DataBindings.Count - 1 To 0 Step -1
            dbd = control.DataBindings.Item(index)
            If dbd.PropertyName = propertyName Then
                control.DataBindings.Remove(dbd)
            End If
        Next
        dbd = New Binding(propertyName, dataSource, dataMember)
        control.DataBindings.Add(dbd)

    End Sub

    Private Sub oBinding_Format(ByVal sender As Object, ByVal e As System.Windows.Forms.ConvertEventArgs) Handles dbd.Format

        e.Value = Format(e.Value, "D")

    End Sub

When I run the app. the dates in the textboxes are formatted correctly, however the textboxes are on a tab control and when I click onto a different tab and then back all the dates show in the format 01/01/2005 00:00:00.

Any ideas? Rob. confused

Paul.Lewis
User
Posts: 147
Joined: 22-Aug-2005
# Posted on: 05-Oct-2005 04:57:33   

FunkyMonkey wrote:

When I run the app. the dates in the textboxes are formatted correctly, however the textboxes are on a tab control and when I click onto a different tab and then back all the dates show in the format 01/01/2005 00:00:00.

Rob,

I have one question and one possible cause:

  • What type tab control are you using?
  • Is your tab control doing a postback for each Active tab change event? If so, are you rebinding your text box controls properly on postback?

Paul

Posts: 11
Joined: 02-Aug-2005
# Posted on: 05-Oct-2005 09:40:03   

My apologies, I should have stated the context.

It's a VB .NET win forms application and I am using the standard MS Tab Control.

Rob.