Formatting a MS Access date/time field in Windows Form column

  • Thread starter Thread starter Amil
  • Start date Start date
A

Amil

I read MS Access records in. The date/time field in my datagrid only
shows the date...does not include the time. Is there a way to format or
get the Column to show the time as well? This is in Windows Forms.

Amil
 
I haven't tested this, but if your datagrid is databound, you could probably
attach a handler to the Format event of the field which you want to format.
The format event is triggered when the value from the database is rendered
to be displayed on the form.

After binding, you would attach the format event for the right field like
this:

AddHandler dgrMyGrid.DataBindings("SomeProperty").Format, AddressOf
MyHandler

And then you would format the value like this:

Private Sub MyHandler(ByVal sender As Object, ByVal e As
ConvertEventArgs)
e.Value = CType(e.Value, DateTime)
End Sub

Whatever you set e.Value to will be displayed on the form.

There's also the Parse event which works in the other direction, thus from
form field to database field.

I don't know if my example is complete, but it should point you in the right
direction.

Hope it works...
 
Back
Top